Applescript/shellscript

Member
Posts: 63
Joined: 2005.04
Post: #1
I want to create a script that runs automatically whenever I launch x code that opens another application. Is this possible?

and

The terminal, is it worth learning? what are some practical examples of it in use?

information.overload
ZZZ
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #2
The terminal is certainly worth learning, although it is by no means required. It can do pretty much anything you want Rasp
If you have no specific reason to want to learn the shell though, it's not like you have to go jump to doing so.

As for the triggered events, I'm sure it's possible but the only way I can think of is to have it continually poll the system to see if the application is open which is an ugly hack and I'm sure there's a better way.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #3
You'd probably be better off writing a script which launches Xcode and your other app at the same time. If you want it to happen when you double click a source file or project, that's a bit trickier, but you can probably get the AppleScript app to pretend that it handles those files and have it redirect the open event to Xcode (you'd need to edit its plist or stick a BNDL resource etc. on it). Either that, or just drag and drop onto the script.

As far as the Terminal goes, I just like playing with it for fun. Wink However, it has lots of potential uses, especially when it comes to programming related tasks such as processing your source or data files.

Here's a sample one-liner (courtesy of OneSadCookie) which I used to count the lines in all my source files in a project which was primarily composed of files with Mac line endings:

Code:
find . -name '*.hpp' -or -name '*.cpp' -print0 | xargs -0 cat | tr '\r' '\n' | wc -l
That's pretty cryptic at first glance, but if you read the man pages ('man find', for example) for each of the commands (find, xargs, cat, tr and wc) you can figure out what's going on with a bit of thought.

Also, understanding shell scripting will help you to understand how the operating system starts up and is automated, and that's quite useful if you want to install certain kinds of software. In my case, I've recently installed Apache 2 and Subversion so that I can run a source code management system on my Mac. To get it all up and running, I had to do quite a lot of fiddling in the command line, and if I hadn't known how to do that I would have been stuck.

You can get by without any knowledge of the command line, but you can do more sophisticated things if you learn a bit about it. Smile

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #4
Check out the open command. In a terminal, type the follwing and hit enter:

open /Developer/Applications/Xcode.app/ /Applications/TextEdit.app/ /Applications/Preview.app/

That will launch 3 applications: Xcode, TextEdit, and Preview.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Accessing iTunes DB through Applescript? blobbo 2 3,498 Dec 30, 2005 06:51 AM
Last Post: blobbo