The following script is intended to open files with the qlmanage utility, but it doesn’t work:
use framework "Foundation"
use scripting additions
set ssFolder to "/Users/Robert/Screenshots/" -- change to folder with image files
set ssFolder to current application's |NSURL|'s fileURLWithPath:ssFolder
set fileManager to current application's NSFileManager's defaultManager()
set folderContents to fileManager's contentsOfDirectoryAtURL:(ssFolder) includingPropertiesForKeys:{} options:4 |error|:(missing value)
set ssFiles to ((folderContents's valueForKey:"path")'s sortedArrayUsingSelector:"localizedStandardCompare:")
set ssFiles to ssFiles's componentsJoinedByString:"' '"
set ssFiles to current application's NSString's stringWithFormat_("'%@'", ssFiles)
--this doesn't work
set commandPath to "/usr/bin/qlmanage"
set commandArguments to {"-p", ssFiles}
set theTask to current application's NSTask's new()
theTask's setLaunchPath:commandPath
theTask's setArguments:commandArguments
set theResult to theTask's launchAndReturnError:(missing value)
--this works
--do shell script "/usr/bin/qlmanage -p " & (ssFiles as text)
The reason it doesn’t work is because each parameter has to be a functional unit (a file path in this instance). I say this because the following works:
use framework "Foundation"
use scripting additions
set ssFileOne to "/Users/Robert/Screenshots/aa aa.png"
set ssFileTwo to "/Users/Robert/Screenshots/bb bb.png"
set commandPath to "/usr/bin/qlmanage"
set commandArguments to {"-p", ssFileOne, ssFileTwo}
set theTask to current application's NSTask's new()
theTask's setLaunchPath:commandPath
theTask's setArguments:commandArguments
set theResult to theTask's launchAndReturnError:(missing value)
Thanks for any suggestions.