Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[AS] doScript with arguments

Guest
Mar 05, 2010 Mar 05, 2010

Hi,

I'm trying to execute a js script through applescript but can't get the syntax right.

I'd like to parse var myFolder to do script. Any hints?

Thanks

// execute js file

set myFile to choose file with prompt "Choose a script"
set myFolder to choose folder with prompt "Choose a folder"
display dialog "myFolder is " & myFolder
tell application "Finder"
     set myFileExt to name extension of myFile
end tell
tell application "InDesignServer"
     if myFileExt is "jsx" then
                --call this method with argument myFolder?
          do script myFile language javascript
     else
               --call this method with argument myFolder?          
               do script myFile language applescript language
     end if
end tell

// js

// print arguments

i = 0;
while (i < withArguments.length) {
     app.consoleout(withArguments);
     i++;
}

TOPICS
Scripting
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2010 Mar 05, 2010

Here below is example for doscript with arguments. Hope it will help you.

--DoScriptReturnValues.applescript

--An InDesign CS4 AppleScript

--

--Shows how to get values back from a script run using

--the do script command.

main()

on main()

     mySetup()

     mySnippet()

     myTeardown()

end main

on mySetup()

end mySetup

on mySnippet()

     tell application "Adobe InDesign CS4"

          --<fragment>

          set nameA to "ScriptArgumentA"

          set nameB to "ScriptArgumentB"

          set nAc to nameA & ": "

          set nBc to nameB & ": "

          --Create a string to be run as an AppleScript.

          set p1 to "tell application \"Adobe InDesign CS4\"" & return

          set p2 to "tell script args" & return

          set p3 to "set value name \"ScriptArgumentA\" value "

          set p4 to "\"This is the first AppleScript script argument value.\""

          set p5 to "set value name \"ScriptArgumentB\" value "

          set p6 to "\"This is the second AppleScript script argument value.\""

          set p7 to "end tell" & return

          set p8 to "end tell"

          set myAppleScript to p1 & p2 & p3 & p4 & return & p5 & p6 & return & p7 & p8

          --Run the AppleScript string.

          do script myAppleScript language applescript language

          --Retrieve the script argument values set by the script.

          tell script args

               set myScriptArgumentA to get value name nameA

               set myScriptArgumentB to get value name nameB

          end tell

          --Display the script argument values in a dialog box.

          display dialog nAc & myScriptArgumentA & return & nBc & myScriptArgumentB

          --Create a string to be run as a JavaScript.

          set p1 to "app.scriptArgs.setValue(\"ScriptArgumentA\", "

          set p2 to "\"This is the first JavaScript script argument value.\");" & return

          set p3 to "app.scriptArgs.setValue(\"ScriptArgumentB\", "

          set p4 to "\"This is the second JavaScript script argument value.\");" & return

          set myJavaScript to p1 & p2 & p3 & p4

          --Run the JavaScript string.

          do script myJavaScript language javascript

          --Retrieve the script argument values set by the script.

          tell script args

               set myScriptArgumentA to get value name nameA

               set myScriptArgumentB to get value name nameB

          end tell

          --Display the script argument values in a dialog box.

          display dialog nAc & myScriptArgumentA & return & nBc & myScriptArgumentB

          --</fragment>

     end tell

end mySnippet

on myTeardown()

end myTeardown

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 05, 2010 Mar 05, 2010

Was this taken from the InDesign sample scripts? In that case I'm sorry for the ignorance

Will give it another go - thanks!

Rasmus

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 05, 2010 Mar 05, 2010

Hi again,

This works:

tell application "Adobe InDesign CS4"
     set line1 to "var s = \"some string\";" & return
     set line2 to "alert(s);"

set myJavaScript to line1 & line2

do script myJavaScript language javascript

But this doesn't:

tell application "Adobe InDesign CS4"
     set line1 to "scriptArgs.setValue(\"arg1\",\"myValue\");" & return
     set line2 to "var value = scriptArgs.getValue(\"arg1\");" & return

     set line3 to "alert(value);"

set myJavaScript to line1 & line2 & line3

do script myJavaScript language javascript

A little help?

Thanks,

Rasmus

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2010 Mar 05, 2010

Try below one

tell application "Adobe InDesign CS4"
     set line1 to "app.scriptArgs.setValue(\"arg1\",\"myValue\");" & return
     set line2 to "var value = app.scriptArgs.getValue(\"arg1\");" & return
     set line3 to "alert(value);"
set myJavaScript to line1 & line2 & line3
do script myJavaScript language javascript

end tell

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 09, 2010 Mar 09, 2010

That did it - thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 09, 2010 Mar 09, 2010

Shonky,

When you post other people's scripts, please write a note that you are doing such.

Thanks,

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 09, 2010 Mar 09, 2010
LATEST

I'll do this Harbs.

Thanks,

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines