Simon icon Simon
Flexible server monitoring

Unable to run applescripts

Hi,

(first post)

I'm currently unable to use applescript notifiers. I have tried using a simple example script provided with Mac OS X (Current Date & Time.scpt) just to be sure the script is ok, but still no luck. I have narrowed it down to a Simon-related problem as every other app including Script editor seem to be able to execute applescripts just fine.

Also, all other notification types run ok, and no errors show up in the logs. Runnig /usr/bin/osascript from terminal works fine. My user account has administrator priviligies.

I have tried anything I can think of, but obviously there is something I have missed.

Running a basic Simon license on OSX 10.5.6 (9G55).

David Sinclair's picture

Re: Unable to run applescripts

Do you have the AppleScript source in the Script window, rather than trying to execute an external file?

Do you have the script method set correctly? (There will be an build button below the source area in AppleScript mode, and the source will be colored appropriately.)

Maybe a screenshot would clarify things.

zanoii's picture

Script type is set to

Script type is set to "AppleScript: /usr/bin/osascript" and the code is in the script window. I was using some Simon variables before, but changed to a less complex script to rule out error sources.

Screen shot (clickable):

Starting to think if there's a possibility localization could have something to do with it. Been experiencing this on two different machines today (PB G4 and MBP C2D) and both had Mac OS X set to Swedish.

I appreciate any help I can get. I would hate to have to do a shell script workaround.

David Sinclair's picture

Re: AppleScript notifier

Ah, I see the problem. You need to wrap the script code in a tell block, to indicate to AppleScript which application should be performing this work. Since the script is executed by the osascript command line tool, it isn't in a UI context.

For displaying a dialog, you could use Simon, or System Events.

e.g.

tell application "System Events"
    -- add your code here
end tell

I suppose I could alter Simon to wrap AppleScripts in a default tell block to avoid this confusion... what do you think?

zanoii's picture

Thank you! I missed that

Thank you! I missed that one. I'm not that good at applescript, but I should have seen something was missing.

Tried this example script which worked:

tell application "Finder"
activate
set visible of every process whose visible is true and name is not "Finder" to false
end tell

So.. the thing I tried to do in the first place is having Simon sending an SMS using a connected phone. BluePhoneElite can do this and has applescript capabilities. (Also, once I get outgoing sms up and running, I'm planning on letting incoming sms control some stuff.. mount/unmount volumes, control lights (via a USB RF transmitter) and more.)

This works fine from script editor (phone number is censored out):

tell application "BluePhoneElite 2"
set theSMSText to "Dummy text."
set theRecipient to "+46*********"
send message theSMSText to theRecipient ¬
using the first device whose available is true
end tell

But it does not work from Simon. Do I have to wrap this in another tell block? If so, what application should be "told" to do it? :) I experimented a little, but with no success.

Similarly, using example scripts to display growl notifications (yes, I know it's redundant since there's a special notification type for Growl) does not work, though it's wrapped in tell blocks (tell application "GrowlHelperApp").

Regarding altering Simon to use a default tell block: Only ok as long as it doesn't break current scripts that people might be using. Since my errors likely is because of my lack of Applescript knowledge, people who know Applescript probably know what needs to be different when scripts are run by osascript. This probably also explains the lack of forum threads on the subject. ;)

David Sinclair's picture

Re: tell application "BluePhoneElite 2"

Hmm... you've got me there. That script looks fine to me. I'm not sure why it wouldn't work from Simon. Does anyone else have any ideas?

Have you tried running it from the Edit Notifier window (via the run button below the script source area)? That will display a Preview window which will show the output and any error. It's a good tool for debugging scripts.

zanoii's picture

When I run it from the

When I run it from the notifier window a new window pops up, with the script in the upper part, nothing in the lower part and "Success" in the "status bar" (at the bottom).

And it runs OK from script editor.

I activated growl logging, and it seems applescript growls from Simon never reaches GrowlHelperApp. Sending a growl notification from Script editor creates a log entry (like the one below), sending from Simon does not.

Mar 29 14:35:25 c-724672d5 GrowlHelperApp[24620]: SimonApplescript registered
Mar 29 14:35:25 c-724672d5 GrowlHelperApp[24620]: SimonApplescript: Test Notification (This is a test AppleScript notification.) - Priority 0

zanoii's picture

Re: tell application "BluePhoneElite 2"

Thank you for your help this far, David. Please let me know if you have any ideas. I'm going to try setting Mac OS X to English now to see if that helps. Unfortunately, that is going to break other things.

David Sinclair's picture

Re: tell application "BluePhoneElite 2"

I don't have any ideas... but if you provide the source you tried for Growl, I'll give it a try to see what happens for me.

zanoii's picture

Sure, here's the Growl code

Sure, here's the Growl code I used:

tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"Test Notification", "Another Test Notification"}
set the enabledNotificationsList to ¬
{"Test Notification"}

register as application ¬
"Simon Applescript" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Simon"

notify with name ¬
"Test Notification" title ¬
"Test Notification" description ¬
"This is a test AppleScript notification." application name "Simon Applescript"
end tell

It's from the Growl developer docs, and just like the other scripts, this works fine from Script Editor.

Thanks.

David Sinclair's picture

Re: Sure, here's the Growl code

Ah, I've figured it out. If you remove the ¬ characters and line breaks, the script works. Those are extended ASCII characters, so apparently aren't being encoded correctly. From memory, the script is turned into UTF-8 encoding, which wouldn't support that character. And without that special character at the end of lines, the line break signifies a new command.

So, workaround for now: remove those characters and line breaks. I'll make a note to investigate the encoding issue to see if I can solve that for the next release.

Your other script also included that character, so this will be the solution for that, too.

zanoii's picture

Success!

Great, your solution works. Thank you very much.

Successfully sent a Growl notification using this script:

tell application "GrowlHelperApp"
set the allNotificationsList to {"Test Notification", "Another Test Notification"}
set the enabledNotificationsList to {"Test Notification"}

register as application "Simon Applescript" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Simon"

notify with name "Test Notification" title "Test Notification" description "This is a test AppleScript notification." application name "Simon Applescript"
end tell

zanoii's picture

Sure, here's the Growl code

This post ended up in the wrong place.. Sorry.