 |
 |
Scripting in OSX
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2010
Status:
Offline
|
|
Hi, i'm a windows user who seek a way to make .bat-like files on mac.
I know about the terminal, but how do you execute some stored script by doubleclicking a file? (like a bat file does)
Also in a bat file, you can get arguments by using %1 %2 %3 etc.. i need this functionality also.
Can someone give me a clue?
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
I'd worry about making the script double-clickable once you have actually created your script.
Google Unix shell scripting, or else tell us more about what the script should do so that we can help you get started.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2010
Status:
Offline
|
|
Hmm.. im talking about simple simple commandlines..
Ok, foran example if i wanted to open a app with an argument:
/Applications/TheApp/TheApp.app/Contents/MacOS/TheApp -file schema1.xml
So, instead of having to open the terminal, and type this.. i'd like for the user just to be able to doubleclick , and the above script fires.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Check out Platypus ( http://www.sveinbjorn.org/platypus), it's a utility that creates executable wrappers out of Unix commands. Last I checked you can also create GUI executable commands with the Terminal app itself.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2010
Status:
Offline
|
|
Ok thanks.
I find it really weird that there's isnt a "native" way to do it..
Well..atleast the software you link to is opensource freeware...for now.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
"native" would be AppleScript or a bash script.
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
And AppleScripts can be compiled as executable apps.
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
There is a native way to do this - a script file with the suffix .command will be opened and executed by Terminal.app like a shell script.
|
|
The low-end Mac Pro is the most overpriced Mac since the IIvx
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
Have you found a way to get the terminal window to close at the end of the script?
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
Seem to remember that if all outputs are redirected away from the terminal, the window closes, but I'm far from certain.
|
|
The low-end Mac Pro is the most overpriced Mac since the IIvx
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Does adding "exit" as the final statement in the shell script close the terminal window?
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
I played around a bit, but I couldn't find a way to do so in the file. You can of course do so in the Terminal settings, but not in the file that I can see.
|
|
The low-end Mac Pro is the most overpriced Mac since the IIvx
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
Completely untested applescript version (On a XP machine ATM) Copy the following into ScriptEditor
tell application "TheApp"
activate
open for access "schema1.xml"
end tell
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally Posted by P
I played around a bit, but I couldn't find a way to do so in the file. You can of course do so in the Terminal settings, but not in the file that I can see.
It's a kludge, but you could end the script with:
osascript -e 'tell application "Terminal" to close the front window'
If having to hit the Return key to dismiss the "Are you sure?" sheet annoys you, you could tack on a second script to simulate a Return keypress using GUI scripting.
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
Well if we permit kludges, just ending the script with "killall Terminal" would work too...with the minor sideeffect of closing all open Terminal windows. Perhaps checking if any other shells were running (count the number of login processes) and only kill Terminal if the current window is the only open one, or something.
Probably best to just end the script with
echo Please close this window now
|
|
The low-end Mac Pro is the most overpriced Mac since the IIvx
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
How about this? Write this AppleScript and save it as an application:
Code:
on run
set myPath to the POSIX path of (path to me as string)
do shell script myPath & "/Contents/Resources/my_script.sh"
end run
Then save a shell script as "my_script.sh" and put it inside the AppleScript application's bundle, in Contents/Resources. This will give you a nicely wrapped shell script using nothing but "native" methods.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|