Mac service to open </path/to/filename>

boeufhead

macrumors newbie
Original poster
Mar 21, 2014
2
0
hello
i'm sure the answer is out there but i've been unable to find it.

i want to make a service using applescript/automator so that when i control click on a text selection in whatever programme it opens the file with the default application and gives me a can't find file dialogue if it can't find the file.

so say this is the selected text
file:///Volumes/filelibrary/testfile.pdf
i want to be able to control click on that text and have a service open the file in preview...

any help much appreciated!
 
Last edited:

kryten2

macrumors 6502a
Mar 17, 2012
996
59
Belgium
any help much appreciated!
Take a look at the open command.

Quote from the man page :

The open command opens a file (or a directory or URL), just as if you had
double-clicked the file's icon. If no application name is specified, the
default application as determined via LaunchServices is used to open the
specified files.

If the file is in the form of a URL, the file will be opened as a URL.
Info : Open Manual Page
 
Last edited:

boeufhead

macrumors newbie
Original poster
Mar 21, 2014
2
0
thank you so much. that is useful... but i was looking to create a service in automator that would act on a text selection.

so say the text selection is file:///Users/testuser/Desktop/testimage.png
i want to be able to control click on that selection and have it open that file.

so i know how to make a service in automator but (and i guess this is a real newbie question...) how do i pass the selected text to a script so that it opens that file when i control click??
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Open is already a system included service, select text in the form of a file path and it will appear in the context menu: services/open or open URL.

But it would be easy to do what you are asking, you need to pick selected text in any program as input, then use the run shell script action, with the open command.