AppleScript: Return a value to the Terminal?

Discussion in 'Mac Programming' started by RachitGupta, Dec 15, 2009.

  1. RachitGupta macrumors newbie

    Joined:
    Dec 15, 2009
    #1
    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
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. RachitGupta thread starter macrumors newbie

    Joined:
    Dec 15, 2009
    #3
    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?
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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)
     
  5. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    Are you wanting to use the string in a variable or just have it immediately print out?
     
  6. RachitGupta thread starter macrumors newbie

    Joined:
    Dec 15, 2009
    #6
    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
     
  7. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    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"
     
  8. RachitGupta thread starter macrumors newbie

    Joined:
    Dec 15, 2009
    #8
    Thanks, I'm getting an error when I run this, though:

    Rachit-Guptas-MacBook:Desktop 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.
     
  9. RachitGupta thread starter macrumors newbie

    Joined:
    Dec 15, 2009

Share This Page