Re: Scripting Bridge and System Events

2008-12-27 Thread has

Kevin Wojniak wrote:


I am trying to write a method to set the Desktop picture using
Scripting Bridge and System Events.
[...]
The working AppleScript is:

set picture of desktop 1 to POSIX file "/Some/file.jpg"



FWIW, running your AppleScript through appscript's ASTranslate tool  
produces the following code:


#import "SEGlue/SEGlue.h"
SEApplication *systemEvents = [SEApplication applicationWithName:  
@"System Events"];

SEReference *ref = [[[systemEvents desktops] at: 1] picture];
id result = [ref setItem: [NSURL fileURLWithPath: @"/Some/file.jpg"]];

Dunno about Scripting Bridge - I have a fairly low opinion of it and  
avoid it myself.


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Scripting Bridge and System Events

2008-12-26 Thread Kevin Wojniak
I am trying to write a method to set the Desktop picture using  
Scripting Bridge and System Events.


Header is generated via:

sdef /System/Library/CoreServices/System\ Events.app | sdp -fh -- 
basename SystemEvents


The working AppleScript is:

set picture of desktop 1 to POSIX file "/Some/file.jpg"

Here's the code I have:

SystemEventsApplication *systemEvents = [SBApplication  
applicationWithBundleIdentifier:@"com.apple.systemevents"];
NSDictionary *props = [NSDictionary dictionaryWithObject:[NSURL  
fileURLWithPath:@"/Some/file.jpg"] forKey:@"URL"];
SystemEventsDiskItem *picture = systemEvents  
classForScriptingClass:@"disk item"] alloc] initWithProperties:props]  
autorelease];

[[systemEvents diskItems] addObject:picture];

When I add it to the diskItems array, it pukes:

*** Terminating app due to uncaught exception 'NSGenericException',  
reason: 'Apple event returned an error.  Event =  
'core'\'crel'{ 'kocl':'ditm', 'insh':'insl'{ 'kobj':'obj  
'{ 'want':'file', 'from':'null'(), 'form':'indx',  
'seld':'abso'($206C6C61$) }, 'kpos':'end ' }, 'prdt':{ 'url ':'furl'("file://localhost/Some/file.jpg 
") } }

Error info = {
ErrorNumber = -1;

I've tried several variations, with using key @"path" and  
@"POSIXPath". I've tried creating the object with just init instead of  
initWithProperties. No luck.


Any tips?

Thanks,
Kevin
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com