Thread View: adobe.scripting.indesign
6 messages
6 total messages
Started by james_hendrickx
Wed, 07 Jan 2009 14:16
[JS,AS,CS3]running javascript in bridge from applescript
Author: james_hendrickx
Date: Wed, 07 Jan 2009 14:16
Date: Wed, 07 Jan 2009 14:16
35 lines
1881 bytes
1881 bytes
Sorry for the cryptic subject description, and you might think this is a bit off topic, but i hope you could shed some light on this.
I need to execute a Javascript in Bridge from an applsecript using an Applescript. Bridge only has one AS command: do javascript with arguments.
My testtude looks like this:
set myJS to "
alert(arguments[0].toString());
alert(arguments[1].toString());
alert(arguments[2].toString());
alert(arguments[3].toString());
alert(arguments[4][0].toString());
"
set arg1 to 12
set arg2 to "some text"
set arg3 to "'some single quoted text'"
set arg4 to "\"some double quoted text\""
set arg5 to {1, 2, 3, "a", "b", "c"}
tell application "Bridge CS3"
do javascript myJS with arguments {arg1, arg2, arg3, arg4, arg5}
end tell
--tell application "Adobe Photoshop CS3"
-- do javascript myJS with arguments {arg1,arg2,arg3,arg4,arg5}
--end tell
You would expect a series of dialogs to appear with the content of the arguments, but you'll get nothing! If you omit the '[0]', you'll get any numerical value, but all strings, however they are quoted, are ignored.
Strange.
Stranger still is, that if do the exact same thing in Photoshop, it works like a charm and you can pass any kind of data as argument.
Any ideas on what's going on?
Thanks!
Re: [JS,AS,CS3]running javascript in bridge from applescript
Author: Kasyan Servetsky
Date: Wed, 07 Jan 2009 19:08
Date: Wed, 07 Jan 2009 19:08
10 lines
1344 bytes
1344 bytes
Hi James, Bridge doesn't support AppleScript, so JavaScript is the only option. But you can run JS in Bride from AS via another Adobe application, for example, InDesign using BridgeTalk. A couple of years ago I did an experiment in Xcode 2.2. The goal was to create a simple interface with Interface Builder � a window with 5 buttons grouped into 2 panels. The buttons have an AS attached to them. And this AS, in turn, triggers a JS from InDesign to Bridge, using BridgeTalk, and sending some parameters in variables. The JS in Bridge writes some metadata and sets label. To demonstrate the approach I�ll post the script in the next post. Kasyan
Re: [JS,AS,CS3]running javascript in bridge from applescript
Author: Kasyan Servetsky
Date: Wed, 07 Jan 2009 19:14
Date: Wed, 07 Jan 2009 19:14
93 lines
4053 bytes
4053 bytes
Here is my AS script from Xcode project: Some text is in Russian � don't mind it. Most important that this is a working example. global myBridgeLabel on clicked theObject if name of theObject is "b1" then set processName to (StringToUnicode "Начало работы") set myBridgeLabel to "Red" set myLabel to 1 else if name of theObject is "b2" then set processName to (StringToUnicode "Сдано на цв-корр") set myBridgeLabel to "Green" set myLabel to 2 else if name of theObject is "b3" then set processName to (StringToUnicode "Сдано на ДТП") set myBridgeLabel to "Yellow" set myLabel to 3 else if name of theObject is "b4" then set processName to (StringToUnicode "Забрано") set myBridgeLabel to "Blue" set myLabel to 4 else if name of theObject is "b5" then set processName to (StringToUnicode "Пересдано") set myBridgeLabel to "Purple" set myLabel to 5 end if tell application "Adobe InDesign CS2" set mydocument to active document set myDocumentPath to full name of mydocument set workerName to "Сервецкий" tell metadata preferences of mydocument set theDate to current date set myWeekday to weekday of theDate as string set myDenNedeli to my convertWeekday(myWeekday) set myRecord to (processName & " � " & workerName & " � ") & myDenNedeli & " " & text 1 thru -4 of time string of theDate & " " set myHistory to get property namespace "http://ns.adobe.com/photoshop/1.0/" path "History" set property namespace "http://ns.adobe.com/photoshop/1.0/" path "History" value myHistory & myRecord end tell set myJavaScript to "var myLabel =\"" & myBridgeLabel & "\"; app.activate(); var bt = new BridgeTalk; bt.target = \"bridge\"; myScript = 'app.displayDialogs = \"none\"; var t = new Thumbnail (File (\"" & myDocumentPath & "\")); var mdata = t.metadata; mdata.namespace = \"http://ns.adobe.com/xap/1.0/\"; mdata.Label = \"' + myLabel + '\";'; bt.body = myScript; bt.send();" do script myJavaScript language javascript tell mydocument to save end tell tell application "Finder" set myFile to a reference to file myDocumentPath set label index of myFile to myLabel end tell end clicked on convertWeekday(myWeekday) if myWeekday = "Monday" then return "Пн" else if myWeekday = "Tuesday," then return "Вторник" else if myWeekday = "Wednesday" then return "Среда" else if myWeekday = "Thursday" then return "Четверг" else if myWeekday = "Friday" then return "Пятница" else if myWeekday = "Saturday" then return "Суббота" else if myWeekday = "Sunday" then return "Воскресенье" else return "N/a" end if end convertWeekday
Re: [JS,AS,CS3]running javascript in bridge from applescript
Author: Shane_Stanley
Date: Wed, 07 Jan 2009 22:41
Date: Wed, 07 Jan 2009 22:41
11 lines
1754 bytes
1754 bytes
On 8/1/09 6:08 AM, "Kasyan Servetsky" <member@adobeforums.com> wrote: > Bridge doesn't support AppleScript, so JavaScript is the only option. Not according to its AS dictionary -- it lists two variations of the "do javascript" command, one for strings and one for files. What James is seeing looks like a bug to me. -- Shane Stanley <sstanley@myriad-com.com.au> AppleScript Pro Florida, April 2009 <http://scriptingmatters.com/aspro>
Re: [JS,AS,CS3]running javascript in bridge from applescript
Author: Kasyan Servetsky
Date: Thu, 08 Jan 2009 08:25
Date: Thu, 08 Jan 2009 08:25
1 lines
815 bytes
815 bytes
It is strange, but I was unable even to open Bridge's dictionary in Script Debugger: When I was trying to add Bridge, it was 'grayed out'.
Re: [JS,AS,CS3]running javascript in bridge from applescript
Author: james_hendrickx
Date: Thu, 08 Jan 2009 09:19
Date: Thu, 08 Jan 2009 09:19
5 lines
1004 bytes
1004 bytes
It does look like a bug, especially because the exact same command sent to photoshop does work as expected... I made a workaround by avoiding the 'with arguments' construction to pass the arguments, therefor i had to place the javascript as a string in my applescript and insert the variables there. It works, but i would have liked the 'cleaner' solution... Anyway thanks for your input...
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads