-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
ConvertImages.applescript
executable file
·47 lines (30 loc) · 1.37 KB
/
ConvertImages.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--- converts images from/to common formats
--- select an image file in finder, choose the format you want to conver to
--- the script uses the 'sips' command to create a new file of your chosen format in the same dir
--- need a workaround for 4 letter extensions (e.g. tiff). note that this script can receive PDF as input.
tell application "Finder"
set pathFile to selection as alias
set pathFile to quoted form of POSIX path of pathFile
set fmt to choose from list {"bmp", "gif", "jpg", "png"} with prompt "Convert to:"
if fmt is false then
error number -128
else
try
set destFolder to do shell script "dirname " & pathFile
set baseName to do shell script "basename " & pathFile
set baseName to text 1 thru -5 of baseName
set destFolder to destFolder & "/" & baseName & "." & fmt
set destFolder to quoted form of destFolder
do shell script "sips -s format " & fmt & " " & pathFile & " --out " & destFolder
on error
display dialog "You did not select an image, or it has failed to convert!" buttons {"Ok"} with icon stop
end try
end if
set doDel to button returned of (display dialog "Delete original?" buttons {"Keep", "Delete"} default button "Delete")
if doDel is "Delete" then
do shell script "rm " & pathFile
else if doDel is "Keep" then
error number -128
end if
end tell
--- http://www.github.com/unforswearing