In an applescript, I receive one filepath that I’ve to open.
The filepath is in the format “/Users/xxx/my/file/to/open.xyz“.
I want to open it with the default program. If it’s an AVI, I need to open it with a video program, if it’s an xls, with excel, …
I tried several things without any success:
--dstfile contains the previous path
tell application "Finder"
activate
open document dstfile
end tell
–>I’m getting the error 1728, telling me that he wasn’t able to get the document
tell application "Finder"
activate
open document file dstfile
end tell
–> Same here
tell application "Finder"
activate
open document POSIX file dstfile
end tell
–> Same here
I’m sure that the file exists because I do this before this code execution:
if not (exists dstfile) then
display dialog "File isn't existing"
end if
I cannot use the synthax open.xyz of to of… because I receive this as a parameter.
Please help I’m desperate :'(
Answer: Based on answers, I end up with this:
set command to "open " & quoted form of dsturl
do shell script command
Your problem here is twofold:
Users:xxx:my:file:to:open.xyz). Expressly declaring your path as POSIX file will solve this. However,TL;DR: the following line will open a file given through a POSIX path in the default program without recourse to the shell:
Caveat: this is the simplest solution, but it will only work for qualified POSIX paths (i.e. those beginning with
/), like the one in the question. Handling relative ones (i.e. paths starting with~,.or..) OTOH needs either the AppleScript-ObjectiveC API (not exactly trivial) or the shell (have fun with your quoting).