|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Launching a Shell Script from Finder
How do you launch a shell script from Finder? I want to be able to run a ".sh" file by just double clicking it. This seems like an easy one, but I can't seem to find the answer.
One catch (which really shouldn't be a problem) is that the script needs to run in the folder where it resides (since the script operates on files in the folder). Oh, and hard coding paths is not acceptable for this situation. I tried saving a ".term" file from Terminal and editing the value for "<key>ExecutionString</key>" to launch my script, but the terminal doesn't run in the current folder (very annoying). I also tried renaming the file extension of the script itself from ".sh" to ".command", but again the script runs in the wrong directory. |
|
#2
|
||||
|
||||
|
blah.sh.command
That is an important thing, .sh just won't work The other thing you need to do is cd. at the top of your script cd /path/to/directory
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide Last edited by LinuxPenguin : March 9th, 2006 at 12:30 PM. |
|
#3
|
||||
|
||||
|
You might want to take a look at DropScript. I don't have the url handy right now, but it should be an easy one to Google.
I'm not sure what you're trying to accomplish, but this may be of help. |
|
#4
|
|||
|
|||
|
After some digging around, I finally found a reasonable hack.
Code:
#!/bin/sh ################################################## # File: doit.sh.command # # Setup: $ chmod +x doit.sh.command # # Mac shell script that runs in the current # # folder when you double click it from Finder. # ################################################## cd "`dirname "$0"`" pwd The $0 variable provides the full path of the file, and the dirname command returns the path to the folder. After the cd command, the script is running in the correct folder. The extra quotes are needed to handle spaces in file or folder names. Now to get my scripts to run the way they should when double-clicked from Finder, I just add the .command extension to all my shell scripts and insert that little one-line cd command. ________ Translate perfect mac browser style colors. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Mac Help > Launching a Shell Script from Finder |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|