Path issues in AppleScript using 'Do shell script'
Posted: 2013-11-21T15:27:47-07:00
Hi,
I'm creating an app on the Mac that uses Applescript and ImageMagick to convert PDF files. At the moment I am using the Terminal to execute the commands like so from within AppleScript, which works :-
tell application "Terminal"
if not (exists front window) then do script ""
do script "convert " & home_path_posix & longName & "'(Black)'.tif -compress lzw -depth 8 -colorspace Gray separated-Black.tif" in front window
repeat
tell application "Terminal" to set BI_ to busy of front window
delay 1
if BI_ is false then exit repeat
end repeat
end tell
From what i've read though a better way to go is 'do shell script' so the Terminal window doesn't get invoked and also so I can port it over to Xcode. I have tried converting the command to this :-
tell application "System Events"
do shell script "usr/local/bin/convert " & home_path_posix & longName & "'(Black)'.tif -compress lzw -depth 8 -colorspace Gray " & home_path_posix & "separated-Black.tif"
end tell
The problem with the 'do shell script' version though is i'm having trouble with paths with the input/output file paths failing. See the error below :-
convert: no decode delegate for this image format `/Users/ant/p001(Black).tif' @ error/constitute.c/ReadImage/552.
convert: no images defined `/Users/ant/separated-Black.tif' @ error/convert.c/ConvertImageCommand/3127." number 1
I'm presuming the error is because of filename path issues.
Anyone able to help with this?
Thanks,
Anthony
I'm creating an app on the Mac that uses Applescript and ImageMagick to convert PDF files. At the moment I am using the Terminal to execute the commands like so from within AppleScript, which works :-
tell application "Terminal"
if not (exists front window) then do script ""
do script "convert " & home_path_posix & longName & "'(Black)'.tif -compress lzw -depth 8 -colorspace Gray separated-Black.tif" in front window
repeat
tell application "Terminal" to set BI_ to busy of front window
delay 1
if BI_ is false then exit repeat
end repeat
end tell
From what i've read though a better way to go is 'do shell script' so the Terminal window doesn't get invoked and also so I can port it over to Xcode. I have tried converting the command to this :-
tell application "System Events"
do shell script "usr/local/bin/convert " & home_path_posix & longName & "'(Black)'.tif -compress lzw -depth 8 -colorspace Gray " & home_path_posix & "separated-Black.tif"
end tell
The problem with the 'do shell script' version though is i'm having trouble with paths with the input/output file paths failing. See the error below :-
convert: no decode delegate for this image format `/Users/ant/p001(Black).tif' @ error/constitute.c/ReadImage/552.
convert: no images defined `/Users/ant/separated-Black.tif' @ error/convert.c/ConvertImageCommand/3127." number 1
I'm presuming the error is because of filename path issues.
Anyone able to help with this?
Thanks,
Anthony