Snip
|
You can use AppleScript to create drag and drop icons fo...
|
---|
Categories |
|
---|
For Snip |
loading snip actions ... |
---|---|
For Page |
loading url actions ... |
set filecount to 0
on open filelist
repeat with i in filelist
set filecount to 1
tell application "Terminal"
set filename to do shell script ¬
"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
do script "emacs " & filename & "; exit"
end tell
end repeat
end open
if filecount < 1 then
tell application "Terminal"
do script "emacs; exit"
end tell
end if
set filename to do shell script ¬
"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
is in there to deal with filenames which have spaces or special characters. POSIX path is the UNIX path of a file; the perl -e replaces /Users/foo/file with spaces in its name with /Users/foo/file\ with\ spaces\ in\ its\ name.
tell application "Terminal"
do script "foo"
end tell
The above will run a script in a Terminal window. But sometimes, you don't want to open a Terminal window. In those cases, use this AppleScript code:
do shell script "foo"
Note that if you've modified your $PATH in your ~/.profile, do shell script won't see your new $PATH. In order to run something that's not in /usr/bin, /bin, /usr/sbin, or /sbin, you'll need to do something like this:
do shell script "source ~/.profile; foo"
That's what to do if you use bash (like me). I'm not sure what you would do if you use tcsh and your $PATH has been edited in your ~/.cshrc.
set filecount to 0
run application "X11"
on open filelist
repeat with i in filelist
set filecount to 1
set filename to do shell script ¬
"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
do shell script "source ~/.profile; xemacs -display :0.0 " & filename & " &"
end repeat
end open
if filecount < 1 then
do shell script "source ~/.profile; xemacs -display :0.0"
end if
This script assumes that the $PATH variable has been altered in ~/.profile to include the directory which xemacs is in.
HTML |
You can use AppleScript to create drag and drop icons for shell scripts or X11 applications. Here's how you would create a drag and drop icon for Emacs in Terminal.app:<ol><li>Launch Script Editor (Applications -> AppleScript -> Script Editor </li><li>Copy and paste this text into a new Script Editor window: <pre><code> set filecount to 0 on open filelist repeat with i in filelist set filecount to 1 tell application "Terminal" set filename to do shell script ¬ "perl -e \"print quotemeta ('" & POSIX path of i & "');\"" do script "emacs " & filename & "; exit" end tell end repeat end open if filecount < 1 then tell application "Terminal" do script "emacs; exit" end tell end if </code></pre></li></ol>Save as an application, and give it the name Emacs.app or something similar. Dragging and dropping a file onto Emacs.app will open the file in Emacs in a new Terminal window. Double-clicking will open Emacs in a new Terminal window.<br><br>This line: <pre><code> set filename to do shell script ¬ "perl -e \"print quotemeta ('" & POSIX path of i & "');\"" </code></pre> is in there to deal with filenames which have spaces or special characters. <tt>POSIX path</tt> is the UNIX path of a file; the <tt>perl -e</tt> replaces <tt>/Users/foo/file with spaces in its name</tt> with <tt>/Users/foo/file\ with\ spaces\ in\ its\ name</tt>. <br><br> Modify the <tt>do script</tt> lines if you want to run a different UNIX command: <pre><code> tell application "Terminal" do script "foo" end tell </code></pre> The above will run a script in a Terminal window. But sometimes, you don't want to open a Terminal window. In those cases, use this AppleScript code: <pre><code> do shell script "foo" </code></pre> Note that if you've modified your $PATH in your ~/.profile, <tt>do shell script</tt> won't see your new $PATH. In order to run something that's not in /usr/bin, /bin, /usr/sbin, or /sbin, you'll need to do something like this: <pre><code> do shell script "source ~/.profile; foo" </code></pre> That's what to do if you use bash (like me). I'm not sure what you would do if you use tcsh and your $PATH has been edited in your ~/.cshrc. <br><br> Here's how you can create an AppleScript to launch X11 applications, using xemacs as an example:<ol><li>Launch Script Editor (Applications -> AppleScript -> Script Editor) </li><li>Copy and paste this text into a new Script Editor window: <pre><code> set filecount to 0 run application "X11" on open filelist repeat with i in filelist set filecount to 1 set filename to do shell script ¬ "perl -e \"print quotemeta ('" & POSIX path of i & "');\"" do shell script "source ~/.profile; xemacs -display :0.0 " & filename & " &" end repeat end open if filecount < 1 then do shell script "source ~/.profile; xemacs -display :0.0" end if </code></pre> This script assumes that the $PATH variable has been altered in ~/.profile to include the directory which xemacs is in. </li></ol> |
---|