Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RachitGupta

macrumors newbie
Original poster
Hi Guys,

I'm starting to learn AppleScript after moving from Windows.

How do I return a string back to the terminal after executing an AppleScript?

Thanks!

-Rachit
 
Hey,

I tried that, I saved it as an executable and then I went in terminal and typed "open test.app" and it opened and closed without outputting anything.

Am I supposed to include anything else in the program code other than that one line?
 
I think you want osascript instead. In Terminal type "man osascript" for more info.

AppleScript is more suited for working with applications, not running as a command-line tool. You might be better off using another language, such as Python or Ruby. What are you trying to do?

Edit: found this (new in Snow Leopard)
osascript now supports the log command; the output will be sent to stderr.
 
Oh, I see.

What I'm trying to do is make an app (cross platform) that has to be able to tell what song you're listening to on iTunes. I don't know C, so I chose to go with Adobe Air because i'm a web developer and can basically write the adobe air app in javascript/html. Adobe Air on mac will call on an applescript via command line to find out what song is currently being played, because I don't see any other way to do it. When on Windows, it'll open a different program that works on Windows via command line.

The reason I chose AppleScript to work with Adobe Air is because finding what the name of the current track being played is very simple in AppleScript, and I couldn't find a simple example in C that I would be able to compile!

-Rachit
 
Yea, AppleScript is the right choice for what you want.

This may do what you need 🙂
Code:
osascript -e "tell application \"iTunes\" to return name of current track"
 
Thanks, I'm getting an error when I run this, though:

Rachit-Guptas-MacBook😀esktop silver$ osascript -e "tell application \"iTunes\" to return name of current track"
2009-12-16 11:56:58.538 osascript[2894:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Young Forever [Ft. Mr. Hudson]

The last line, however, is the song that I'm listening to.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.