1

I have an AppleScript that I am trying to convert to ScriptingBridge. Since my application is a C++/Obj-C application, ScriptingBridge is much easier to use and quite a bit faster (not to mention I hate dynamically building AppleScripts).

The AppleScript sends a message to Photoshop to open a file. The file parameter is sent as an alias, but ScriptingBridge imports the parameter as an id. I don't know what Obj-C object I should pass in?

I've tried passing an NSURL and an NSString (probably incorrectly :-P), but to no avail. Any suggestions on what I should be passing for the file alias?

3 Answers 3

1

The short answer is that you can't open documents in Photoshop with Scripting Bridge.

Apple's docs really spell it out like it is. All classes must have a container, which is a mutable array, that they need to be added to before they can be acted upon, as shown in the generated header...

@interface photoshopCS4Application : SBApplication

- (SBElementArray *) documents;
- (SBElementArray *) fonts;
- (SBElementArray *) notifiers;

... and that is the complete list of top-level containers available to us. The open command requires a photoshopCS4OpenOptions to be generated and populated. Because the API doesn't expose the array to store the newly created photoshopCS4OpenOptions object, we can't use a newly created photoshopCS4OpenOptions object. Therefore we can't make a target document and by extensions can't use the open command in Scripting Bridge. The same can be said of all the commands that require some kind of options object.

The only workaround that I have sorted out is to either open a document with native Applescript called from Cocoa or objc-appscript, and then parse the documents array looking for the one just opened. It's not ideal, but then neither is Scripting Bridge because it requires application developers write their scripting APIs in a very specific way that is not native to the OSA framework.

Sign up to request clarification or add additional context in comments.

Comments

1

If your program is such that opening a Photoshop document can be executed outside your AppleScript script/Scripting Bridge code, Cocoa provides a method to open files with a specific application:

[[NSWorkspace sharedWorkspace] openFile:@"/Users/bavarious/Desktop/test.psd" withApplication:@"Adobe Photoshop CS4"];

or, if you want to use the default application that handles that file type, you can drop the application name altogether:

[[NSWorkspace sharedWorkspace] openFile:@"/Users/bavarious/Desktop/test.psd"];

1 Comment

Cool, that's another, arguably better, way than I proposed. The caveat is that the OP still has to go through the documents array to look for the one that was just opened, if opened successfully.
0

Consider Appscript. http://appscript.sourceforge.net/

Here's the code using that:

APApplication *adobePhotoshopCs4 = [APApplication applicationWithName: @"Adobe Photoshop CS4"]; id result = [[adobePhotoshopCs4 open_] send];

(Note, I'm not a Cocoa programmer - I mainly use Appscript with Python but Appscript comes with ASTranslate which translates Applescript into Python, Ruby or Obj-C and that's the output - but I've found there are subtle mistakes in the past sometimes with the translator)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.