Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > File that does a Terminal command?

File that does a Terminal command?
Thread Tools
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Apr 30, 2002, 10:25 PM
 
Can anyone tell me how to make a file that I can double click on and it will do a Terminal command? I'd prefer to stay away from AppleScript. Isn't this what a shell script does? I tried modifying an existing one, but it doesn't seem to like be clicked on :/ Thanks in advance.
     
[email protected]
Senior User
Join Date: Oct 2000
Location: oakland, ca usa
Status: Offline
Reply With Quote
Apr 30, 2002, 10:42 PM
 
check this out (xml below) - just change the <string> below the key 'ExecutionString' to point to your shell script.

or maybe i heard you could name a shell script with a '.sh' extension for double clicking heaven.

but you can save the text below (or save any custom terminal) and then edit it in text editor in the 'ExecutionString' string...just be sure to save it as a '.term' - and be sure to keep the return in there (before the '</string>,' if you want it to execute.


------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>WindowSettings</key>
<array>
<dict>
<key>AutoFocus</key>
<string>YES</string>
<key>Autowrap</key>
<string>YES</string>
<key>Bell</key>
<string>NO</string>
<key>BlinkCursor</key>
<string>NO</string>
<key>Columns</key>
<string>80</string>
<key>CursorShape</key>
<string>0</string>
<key>CustomTitle</key>
<string>Terminal</string>
<key>DisableAnsiColors</key>
<string>NO</string>
<key>DoubleBold</key>
<string>YES</string>
<key>ExecutionString</key>
<string>top -u -s 5 10
</string>
<key>FontHeightSpacing</key>
<string>1</string>
<key>FontWidthSpacing</key>
<string>1</string>
<key>IsMiniaturized</key>
<string>NO</string>
<key>Keypad</key>
<string>NO</string>
<key>Meta</key>
<string>-1</string>
<key>NSFixedPitchFont</key>
<string>Monaco</string>
<key>NSFixedPitchFontSize</key>
<real>1.000000e+01</real>
<key>Rows</key>
<string>19</string>
<key>SaveLines</key>
<string>10000</string>
<key>Scrollback</key>
<string>YES</string>
<key>Shell</key>
<string></string>
<key>ShellExitAction</key>
<string>1</string>
<key>SourceDotLogin</key>
<string>YES</string>
<key>StrictEmulation</key>
<string>NO</string>
<key>TerminalOpaqueness</key>
<real>8.500000e-01</real>
<key>TextColors</key>
<string>0.990 1.000 0.018 0.000 0.000 0.000 0.796 0.594 0.352 0.796 0.594 0.352 0.000 0.000 0.000 0.990 1.000 0.018 0.453 0.464 0.452 0.696 0.696 0.696 </string>
<key>TitleBits</key>
<string>3</string>
<key>Translate</key>
<string>YES</string>
<key>WinLocULY</key>
<string>1178</string>
<key>WinLocX</key>
<string>951</string>
<key>WinLocY</key>
<string>0</string>
</dict>
</array>
</dict>
</plist>
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 30, 2002, 11:07 PM
 
Just give the file the ".command" filename extension. then you can double click on it to open and run it in the terminal.
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
May 1, 2002, 12:36 AM
 
I'm not sure why you want to stay away from AppleScript. It's so easy to use and doesn't need to open Terminal to do it.

Alternatively, you could install Script Menu and you can run shell scripts from that.
     
[email protected]
Senior User
Join Date: Oct 2000
Location: oakland, ca usa
Status: Offline
Reply With Quote
May 1, 2002, 12:49 AM
 
yeah, save this applescript as an application (replacing the cat command with your own shell script)...

on run
do shell script "/bin/cat /etc/motd"
end run
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
May 1, 2002, 01:21 AM
 
If you just want to run a command with no arguments, you can just give the command a creator code of trmx. For example, you could set /usr/bin/top's creator code to trmx, and then you could double click on it and it would bring up the Terminal, with the top command running.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Synotic  (op)
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
May 1, 2002, 02:13 AM
 
The .command suggestion seems perfect, and actually works, but it has to launch the Terminal? I just want it to do its function and that's it, not have to launch anything extra.

As for AppleScript, I am already very fluent with it, enough to know that I don't want an applet launching when this is meant to match the speed of opening a folder and that I don't want to have to make a background only AS-S app because it'd be no doubt even slower. Also, I need it to be a file (it will be faked as a folder), so a menu item won't do.

I have yet to try the XML idea (I can get rid of all that extra crap right?.. TerminalOpaqueness??) and the creator type one, but I will very soon.

Thanks for all your suggestions.
     
[email protected]
Senior User
Join Date: Oct 2000
Location: oakland, ca usa
Status: Offline
Reply With Quote
May 1, 2002, 03:08 AM
 
i don't think you'll care much for the xml hack - it's just a custom terminal set that executes the command on launch. it's an example.

i think the only transparent double-click method for invoking shell scripts, perl scripts, etc. currently available is via applescript, or an actual cocoa/carbon application...you want some kind of shell wrapper app-maker (save as shell script application).

i'm pretty used to unix, so i launch my shell scripts in the shell.

this runs fast (until i try to launch it as an applet, then it is indeed slow to launch):

set foo to do shell script "curl -s <A HREF="http://www.stuped.com/cgi/remote_addr.cgi"" TARGET=_blank>http://www.stuped.com/cgi/remote_addr.cgi"</A>
display dialog foo

what are you trying to run?
     
kovacs
Mac Elite
Join Date: May 2001
Location: Belgium
Status: Offline
Reply With Quote
May 1, 2002, 03:59 AM
 
I am searching for an app or script that excecutes this command when I start OSX; sudo ipfw add 0 deny udp from any to any 2222 and
sudo ipfw add 0 deny tcp from any to any 3464, it aks for your password and it would be nice if this was all automized. These commands block a network port so that I can use MS Office on more than one mac at the same time. I have no experience with shell scripts or applescripts so please keep it simple

TIA
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
May 1, 2002, 07:40 AM
 
If you only want it to run once, and don't want to have to run it yourself, how about making it a StartupItem? That way you don't even have to think about it.

<font face = "courier">
sudo -s
mkdir /Library/StartupItems
mkdir /Library/StartupItems/ShareOffice
</font>

Then
<font face = "courier">
cd /Library/StartupItems/ShareOffice
pico ShareOffice
</font>

In that file, enter the text:
<font face = "courier">
#!/bin/sh
#Startup the common code
. /etc/rc.common

#Block Office's license protection
ConsoleMessage "Enabling Shared Office v.X"
ipfw add 0 deny udp from any to any 2222
ipfw add 0 deny tcp from any to any 3464
</font>

Press ctrl-O, then ctrl-X to save and exit. Then make another file:
<font face = "courier">
pico StartupParameters.plist
</font>
And in that file, type:
<font face = "courier">
{
Description = "Enable Sharing Office v.X on the network";
Provides = ("ShareOffice");
Requires = ("Network");
OrderPreference = "Last";
Messages =
{
start = "Enabling Sharing of Office v.X";
stop = "Disabling Sharing of Office v.X";
};
}
</font>
and command-O command-X again.
That should work.
     
kovacs
Mac Elite
Join Date: May 2001
Location: Belgium
Status: Offline
Reply With Quote
May 1, 2002, 08:25 AM
 
Wow thanks Mithras it seems to work... You made my day ...
     
Synotic  (op)
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
May 1, 2002, 05:53 PM
 
Originally posted by [email protected]:
<STRONG>this runs fast (until i try to launch it as an applet, then it is indeed slow to launch)</STRONG>
Which of course is the problem.. :/ I guess I'll write a background Cocoa app that does what I want after reopening.
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
May 1, 2002, 07:20 PM
 
What is it you're trying to do, Synotic? Maybe folks can come up with some other approaches if you let on to your secret plan...
     
moki
Ambrosia - el Presidente
Join Date: Sep 2000
Location: Rochester, NY
Status: Offline
Reply With Quote
May 1, 2002, 07:41 PM
 
Originally posted by Synotic:
<STRONG>As for AppleScript, I am already very fluent with it, enough to know that I don't want an applet launching when this is meant to match the speed of opening a folder and that I don't want to have to make a background only AS-S app because it'd be no doubt even slower. Also, I need it to be a file (it will be faked as a folder), so a menu item won't do.</STRONG>
In that case, I suggest you write yourself a shell or Perl script. Both are quite easy to learn.
Andrew Welch / el Presidente / Ambrosia Software, Inc.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:20 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,