Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript with widget.system



> AppleScript wants newlines.  If you were able to get error reporting, you'd
> find that it was complaining like this:
> 
> 25:26: syntax error: Expected end of line but found unknown token. (-2741)
> 
> Try:
> 
>     var commandLine = "/usr/bin/osascript -e 'tell application
> \"Mail\"\nactivate\nend tell\n'";
>     widget.system(commandLine, null);
> 
> The system call just hands whatever your command is over to /bin/sh for
> interpretation, though by that time your Javascript will have already done
> some: \" to " and \n to a real newline and so forth.  So you can always test
> on the command line.  Also, system will for a process for every call, so I'd
> generally prefer to do this in objC anyway:


This is not exactly correct.  The system call will try to exec the command
directly unless the command has metacharacters in it.  If it has
metacharacters it will then use /bin/sh.

Thanks,
jl


> 
> - (void)activateMail;
> {
>     NSString *scriptSource = 
>         @"tell application \"Mail\"\n"
>         "  activate\n"
>         @"end tell\n";
>     
>     NSAppleScript *script = [[NSAppleScript alloc]
> initWithSource:scriptSource];
>     NSDictionary *error = nil;
>     [script executeAndReturnError:&error];
>     [script release];
>     if (error) {
>         NSLog(@"error = %@", error);
>     }
> }
> 
> It gives you error reporting.  If your script is expected to return results,
> you can get them from the return of executeAndReturnError:
> 
> -Tom
> 
> On May 19, 2005, at 5:50 AM, John Goodman wrote:
> 
>> Hello,
>> 
>> I am having inconsistent success using widget.system to execute AppleScript
>> commands.
>> 
>> For example, this code works -
>> 
>> var commandLine = "/usr/bin/osascript -e 'tell application \"TextEdit\"
>> activate end tell'";
>> widget.system(commandLine, null);
>> 
>> However, it doesn't work for all applications. If I substitute "iTunes" or
>> "Safari" for "TextEdit", it will launch the named application. But, it
>> *won't* work if I use the names "Preview" or "Mail". Most importantly, it
>> won't work with the application that I have written which I need to access
>> with my widget. If I use Script Editor, I can launch any of these
>> applications with this AppleScript command.
>> 
>> I don't want to use widget.openApplication because I want leave the Dashboard
>> and my widget active, so that I can use my widget to send additional
>> AppleScript commands to the open application.
>> 
>> Thanks for any tips.
>> 
>> 
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Dashboard-dev mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/dashboard-dev/email@hidden
>> 
>> This email sent to email@hidden
>>  
> 
> 
> 
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Dashboard-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/dashboard-dev/email@hidden
> 
> This email sent to email@hidden


--------------------------------------------------
John Louch         Internet #: email@hidden
(805) 541 2965


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: AppleScript with widget.system (From: Tom Bunch <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.