5 Replies Latest reply on Jan 8, 2009 1:19 AM by (james_hendrickx)

    [JS,AS,CS3]running javascript in bridge from applescript

    Level 1
      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!
        • 1. Re: [JS,AS,CS3]running javascript in bridge from applescript
          Kasyan Servetsky Level 5
          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 Ill post the script in the next post.

          Kasyan
          • 2. Re: [JS,AS,CS3]running javascript in bridge from applescript
            Kasyan Servetsky Level 5
            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
            • 3. Re: [JS,AS,CS3]running javascript in bridge from applescript
              sstanleyau Level 4
              On 8/1/09 6:08 AM, "Kasyan Servetsky" <member@adobeforums.com> wrote:<br /><br />> Bridge doesn't support AppleScript, so JavaScript is the only option.<br /><br />Not according to its AS dictionary -- it lists two variations of the "do<br />javascript" command, one for strings and one for files. What James is seeing<br />looks like a bug to me.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
              • 4. Re: [JS,AS,CS3]running javascript in bridge from applescript
                Kasyan Servetsky Level 5
                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'.
                • 5. Re: [JS,AS,CS3]running javascript in bridge from applescript
                  Level 1
                  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...