Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2009, 10:29 PM   #1
RachitGupta
macrumors newbie
 
Join Date: Dec 2009
AppleScript: Return a value to the Terminal?

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
RachitGupta is offline   0 Reply With Quote
Old Dec 16, 2009, 12:18 AM   #2
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
Use return:
Code:
return "hello world"
kainjow is offline   0 Reply With Quote
Old Dec 16, 2009, 12:23 AM   #3
RachitGupta
Thread Starter
macrumors newbie
 
Join Date: Dec 2009
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?
RachitGupta is offline   0 Reply With Quote
Old Dec 16, 2009, 12:36 AM   #4
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
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)
Quote:
osascript now supports the log command; the output will be sent to stderr.

Last edited by kainjow; Dec 16, 2009 at 01:11 AM.
kainjow is offline   0 Reply With Quote
Old Dec 16, 2009, 12:26 PM   #5
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Indianapolis, for an unknown time
Quote:
Originally Posted by RachitGupta View Post
How do I return a string back to the terminal after executing an AppleScript?
Are you wanting to use the string in a variable or just have it immediately print out?
xStep is offline   0 Reply With Quote
Old Dec 16, 2009, 01:36 PM   #6
RachitGupta
Thread Starter
macrumors newbie
 
Join Date: Dec 2009
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
RachitGupta is offline   0 Reply With Quote
Old Dec 16, 2009, 01:44 PM   #7
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
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"
kainjow is offline   0 Reply With Quote
Old Dec 16, 2009, 01:53 PM   #8
RachitGupta
Thread Starter
macrumors newbie
 
Join Date: Dec 2009
Thanks, I'm getting an error when I run this, though:

Rachit-Guptas-MacBookesktop 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.
RachitGupta is offline   0 Reply With Quote
Old Dec 16, 2009, 02:23 PM   #9
chown33
macrumors 601
 
Join Date: Aug 2009
Google it. Search terms: ScriptingAdditions Adobe Unit Types

From the first page of results:

http://blogs.adobe.com/jnack/2009/09...ith_ps_sl.html

http://www.davidchinphoto.com/snow-l...it-types-osax/
chown33 is offline   0 Reply With Quote
Old Dec 16, 2009, 02:45 PM   #10
RachitGupta
Thread Starter
macrumors newbie
 
Join Date: Dec 2009
Ah, thank you very much!
RachitGupta is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting 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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Elegant way to cycle through NSArray from middle index value to the one preceding it? GorillaPaws Mac Programming 8 Aug 17, 2011 11:08 PM
The Terminator Had Love Child with his Maid Huntn Politics, Religion, Social Issues 38 May 21, 2011 12:53 PM
Terminal, add text to the end of all text files in a directory. Jesse Smith Mac Basics and Help 2 Feb 22, 2011 02:13 PM
A Guide to the Terminal, bash, and the UNIX side of Mac OS X wrldwzrd89 Mac OS X 20 Nov 25, 2009 04:59 PM
Switching from Mac OS X to the terminal (like XWindows to Terminal 2 in Linux/Unix) awulf Mac Help/Tips 1 Dec 6, 2002 08:27 PM


All times are GMT -5. The time now is 10:31 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC