Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create a drag and drop interface to shell scripts UNIX
I didn't come up with this hint, but have used it enough so as to submit it. A lot of people have created application "wrappers" for shell scripts using either dropscript or iHook. However they don't always do the job like you may wish. An alternative is to use Applescript.

For instance if you wish to run a Unix command on each file you drop on the Applescript you can do the following:
on open filelist
repeat with i in filelist
do shell script "my_command " & POSIX path of i
end repeat
end open
A nice feature of OSX is that you can associate any application with a kind of file. First save your script using Script Editor as an application. Then select a file of the type you wish to associate with your script. Select "Get Info." Select the "Open with" pane and then select your Applescript application. Click the "Change All" button. Now every file of that extension will open up with your Applescript.

This is very nice for running some shell command on the file for filtering it before opening it with another file. For instance, you can use the following script to open PostScript files in Acrobat. It works by using ps2pdf (available as part of Fink) to first convert the file to a temporary PDF file. You can obviously make this a little more robust if you open multiple PostScript files at the same time.
on open input_file
do shell script "export PATH=\"$PATH\":/sw/bin;ps2pdf \"" &
POSIX path of input_file & "\" ~/.psview.tmp.pdf; open ~/.psview.tmp.pdf"
end open
The "do shell script" command is shown on two lines; enter it as one line with a space after the "&".

[Editor's note: I have not tested this hint myself.]
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[13,443 views]  

Create a drag and drop interface to shell scripts | 3 comments | Create New Account
Click here to return to the 'Create a drag and drop interface to shell scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
BUG fix - posix path needs to be quoted
Authored by: Krioni on Nov 26, '02 01:43:04PM

Posix Path used to include escaped characters so spaces, etc would survive on the shell. In OS X 10.2, at least (and maybe elsewhere), you need to use <b>quoted form of Posix Path</b>, rather than just <b>Posix Path</b>:

<pre>
on open filelist
repeat with i in filelist
do shell script "my_command " & quoted form of POSIX path of i
end repeat
end open
</pre>

With just Posix Path you'll get errors whenever the path includes something the shell doesn't like.



[ Reply to This | # ]
BUG Fix - Posix Path not enough
Authored by: Krioni on Nov 26, '02 01:48:35PM
[reposted for correct formatting]

Posix Path used to include escaped characters so spaces, etc would survive on the shell. In OS X 10.2, at least (and maybe elsewhere), you need to use quoted form of Posix Path, rather than just Posix Path:

on open filelist
repeat with i in filelist
do shell script "my_command " & quoted form of POSIX path of i
end repeat
end open

With just Posix Path you'll get errors whenever the path includes something the shell doesn't like.

[ Reply to This | # ]
BUG Fix - Posix Path not enough
Authored by: ClarkGoble on Dec 30, '02 03:24:25PM
If you add the "quote form" to the Posix make sure you modify your scripts accordingly. For instance the .ps -> .pdf filter/opener I gave will stop working. That's because I added the quotes myself. If you want to use that filter I wrote change it to:
on open input_file do shell script "export PATH="$PATH":/sw/bin;ps2pdf" & POSIX path of input_file & " /tmp/.psview.tmp.pdf" do shell script "open /tmp/.psview.tmp.pdf" end open
Note that I also change the location of the temporary file to be in the /tmp directory. That directory deletes all files older than two weeks. So it is a good place to put a .pdf file rather than hidden in you home directory. That may save you are few hundred k.

[ Reply to This | # ]