Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Applescript

Author Message
macmanluke



Joined: 15 Apr 2005
Posts: 16
Location: SA

Posted: Fri Apr 15, 2005 - 5:20 am    Post subject: Applescript Reply with quote

How can i run applescript from a widget,

I have tried this :-

var obj = widget.system("osascript /itunes_play.scpt");
alert(obj.outputString);
View user's profile Send private message Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri Apr 15, 2005 - 7:29 am    Post subject: Reply with quote

I'm going to guess that itunes_play.scpt is in the widget bundle rather than at the root of your hard drive. It may also help to use the full path name to tools you use (use whereis in the terminal). i.e.

var obj = widget.system("/usr/bin/osascript itunes_play.scpt", null);
alert(obj.outputString);

Assuming your javascript file is in the same directory as the applescript.

Oh yeah, and you forgot the second argument to widget.system too Smile
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
macmanluke



Joined: 15 Apr 2005
Posts: 16
Location: SA

Posted: Fri Apr 15, 2005 - 7:47 am    Post subject: Reply with quote

Thanks! Works perfectly now!!
View user's profile Send private message Widgets
Da_Vinci



Joined: 26 Apr 2005
Posts: 100

Posted: Tue Aug 02, 2005 - 4:38 pm    Post subject: Reply with quote

(How can/) Can I pass information from Applescript to Javascript?

AdiumList does it by writing the returned information in a text file:
Code:
cmdGetList = widget.system("/usr/bin/osascript scripts/get_list_hide_offline.scpt > contactList.txt", procList);

But is there a way to pass it directly?

(Sorry - I'm not very familiar with javascript ^^)
View user's profile Send private message Send e-mail Widgets
Ludge



Joined: 09 May 2005
Posts: 98
Location: UK

Posted: Wed Aug 03, 2005 - 1:54 am    Post subject: Reply with quote

Da_Vinci,
Code:
returnedString = widget.system("/usr/bin/osascript myScript.scpt", null).outputString


Will put the returned data into a variable "returnedString".

See This Apple page for more info on the widget.system() method.[/url]
_________________
BatteryInfo widget
AdiumList widget.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
Da_Vinci



Joined: 26 Apr 2005
Posts: 100

Posted: Wed Aug 03, 2005 - 5:03 am    Post subject: Reply with quote

Ludge wrote:
Da_Vinci,
Code:
returnedString = widget.system("/usr/bin/osascript myScript.scpt", null).outputString


Will put the returned data into a variable "returnedString".

See This Apple page for more info on the widget.system() method.[/url]


Thanx I'll take a look!
View user's profile Send private message Send e-mail Widgets
Joel



Joined: 05 May 2005
Posts: 18

Posted: Wed Aug 03, 2005 - 10:00 am    Post subject: Reply with quote

Be careful, though. There are a few things to know when dealing with .outputString. 1) It adds a newline character at the end, which you need to strip. For example, if I am having applescript return the name of the front process (TextEdit, for example) it'll actually return "TextEdit " or something like that, which you need to clip to get it to work. Also, other people on this board have talked about a 4K limit to the size of the output string, so if you plan to get near that size, you should use the read/write to a file method. Finally, if you are using High ASCII+ characters (accents, unicode, etc.) they could easily become jibberish in the .outputString also, so in that case you need to write to a file also.
View user's profile Send private message Send e-mail Widgets
Da_Vinci



Joined: 26 Apr 2005
Posts: 100

Posted: Thu Aug 11, 2005 - 5:07 am    Post subject: Reply with quote

How can you send information from Javascript to Applescript?
Let's say the content of a variable defined in Javascript?
View user's profile Send private message Send e-mail Widgets
Da_Vinci



Joined: 26 Apr 2005
Posts: 100

Posted: Thu Aug 11, 2005 - 6:00 am    Post subject: Reply with quote

Looks like I found it out myself:

http://www.macosxhints.com/article.php?story=20050523140439734
Quote:
Pass Command-Line Arguments to AppleScript Scripts ?

The command-line osascript tool allows you to execute AppleScript scripts from the command-line. In Mac OS X 10.0 through 10.3, the only argument you could pass to osascript was the script to execute. In Tiger, you can now pass along arguments to pass to the script itself.

From the osascript man page:

Any arguments following the script will be passed as a list of strings to
the direct parameter of the ``run'' handler. For example:

a.scpt:
on run argv
return "hello, " & item 1 of argv & "."
end run

% osascript a.scpt world
hello, world.
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group