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

Using a button in dashcode to trigger an applescript

Author Message
willb



Joined: 24 May 2010
Posts: 3

Posted: Mon May 24, 2010 - 9:54 am    Post subject: Using a button in dashcode to trigger an applescript Reply with quote

Im hoping someone can help a newbie in the world of dashcode. I have been trying to figure this out on my own for some days now and im finally giving in and hoping someone can give me a jump start. My focus is really to learn programming in javascript as well as cocoa objective C.

For now, using javascript I am trying to do a simple task in making a widget that will turn the hidden icons in the finder on and off.

I have copied this code from chris in another topic similar to my own.

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

of course i changed the path but in the end i am not getting any result. not even an error message. The applescript I am using simply tells finder to hide icons and then relaunches the finder for the change to take effect. I have two buttons and another applescript to reverse the process.

In my attempts to troubleshoot I changed the path to "/scriptname" thus putting my script at the root directory just to make sure there were no mishaps in the path. again no results when i test the widget.

I also attempted to use the terminal command using this code

var obj = widget.system("defaults write com.apple.Finder AppleShowAllFiles NO", null);
var obj = widget.system("killall finder", null);

Now, im not sure if I have to put both terminal commands in one function call or was this already correct in having two separate calls? Regardless, I still have no results.

Can someone help? Ultimately I'd like to learn both ways of accomplishing the same task.
View user's profile Send private message Widgets
Hawkman



Joined: 12 Jun 2005
Posts: 28
Location: Derby, UK

Posted: Tue May 25, 2010 - 5:58 am    Post subject: Reply with quote

Does your widget have privileges to run system commands / access files? (Widget Attributes)

You don't have to separate with two calls. You can use a semicolon, ";", to separate the two commands in a single line: "defaults write com.apple.Finder AppleShowAllFiles NO; killall finder".

See Apple's documentation for more information about widget.system.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
willb



Joined: 24 May 2010
Posts: 3

Posted: Tue May 25, 2010 - 9:24 am    Post subject: Reply with quote

Awesome! Thanks for the tip Hawkman. Very Happy btw I read and duplicated your tutorial about making multiple RSS feeds in one widget. Fantastic!

To indicate how new I am, it took me awhile to realize what you were referring to regarding "Widget Attributes". Found it and changed the settings. Unfortunately no success. I did notice a change though, before when I run the widget then press the button. The widget would lock up showing the depressed button and never releasing. I'd wait for awhile then just stop the widget and try something new. This time I see the widget button competing the effect but still no results in the finder.

You probably assumed this as I already stated that I am not getting error messages, but just to inform you, I have also added the tag lines to the info.plist as follows...

Code:

   <key>widget.system</key>
   <integer>1</integer>


Thanks for helping. Here is the updated code as of now.
Code:

function hideIcons(event)
{
    var obj = widget.system("defaults write com.apple.Finder AppleShowAllFiles NO; killall finder", null);
}

function showIcons(event)
{
    var obj = widget.system("defaults write com.apple.Finder AppleShowAllFiles YES; killall finder", null);
}

[/code]
View user's profile Send private message Widgets
kaiyara



Joined: 21 Jun 2013
Posts: 1

Posted: Fri Jun 21, 2013 - 4:49 am    Post subject: Reply with quote

I am probably missing something pretty simple, but I can't make this work:

I want to place radio buttons on the back of a widget that will allow the user to select which "front" to display (yes, using a different id) when the user clicks the "Done" button.
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