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


Click here to return to the 'A shell/AppleScript interaction trick' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A shell/AppleScript interaction trick
Authored by: gshenaut on Jun 21, '04 11:10:00AM
Here's the niftiest application of this idea I've come up with so far. This tiny little script
exec osascript <<EOF
tell app "$*"
	activate
end tell
can be used to start up any gui application from the command line. I call it "run", but another name might be preferable. It must be in your path and made executable.

For example:

run textedit
run microsoft word
run activity monitor
run quicken 2004
run poser 5.0 os x
run finale 2004b
run logic pro 6.4.2
Now, some of these could profit from additional scripting, such as causing them to open files, set templates/modes/etc, but for a quick-and-dirty CLI interface to the GUI apps, this works very well.

Note: you have to type the whole name of the app, which sometimes includes version numbers and so on.

Greg Shenaut

[ Reply to This | # ]

A shell/AppleScript interaction trick
Authored by: gshenaut on Jun 21, '04 11:17:18AM
Just a quick addendum: you can replace the "activate" with other standard applescript commands, for example "quit", and make a script of that name or some other appropriate name. Then you can say things like:
quit textedit
quit mozilla
and so on. Just a random thought. Greg Shenaut

[ Reply to This | # ]
open
Authored by: hayne on Jun 21, '04 04:05:45PM

The same functionality is available via the standard 'open' command (/usr/bin/open).
E.g.:
open -a TextEdit

Do:
man open
for more details.



[ Reply to This | # ]
open
Authored by: gshenaut on Jun 21, '04 05:55:17PM
That's similar, but not identical functionality. It needs the -a and quotes around names containing spaces, and it can't do things like "quit". Also, since it's a script, it's possible to make other customizations on "run", such as looking up the full name in a table, so you can say "run word" instead of "run microsoft word":
exec osascript <<EOF
tell app "`grep $1 < ~/etc/longnames`"
	activate
end tell

Greg Shenaut

[ Reply to This | # ]

automaitc "longnames" list
Authored by: nick on Jun 27, '05 10:19:15AM

i figured out this one:

[code]
#!/bin/sh

exec osascript <<EOF
tell app "`ls /Applications/* | grep \.app | awk -F .app '{print $1}' | sed s/'\/Applications\/'/''/ | grep -i $1 | head -1`"
activate
end tell
[/code]
so i don't have to maintain the "longnames" list.



[ Reply to This | # ]