3 Replies Latest reply on Dec 14, 2008 8:45 AM by Eric @ MCA

    How to call applescript values?


      Now am working in indesign CS2 Scripting.. I need to call a applescript.. so that i used doScript..

      i have 2 doubts...

      1) If i choose a file in the javascript, the file path structure is like "~/Desktop/New/1.jpg". I need to get the full parent folder path of file.. is it possible???

      2) If i set a value to a variable in applescript.. how do i call the value from the javascript??? using doScript???

      Thanks in advance..

        • 1. Re: How to call applescript values?
          Eric @ MCA Level 3
          I know very little about JS, but these are fairly easy to accomplish in AS.

          [1] get path to home folder

          will return the equivalent of the "~" path.

          Or in your specific example to get an image in the desktop folder you could also use something like:

          set myPath to ("" & (path to desktop folder) & "New:1.jpg")

          If you want it returned with slashes instead of colons in the path, add posix path of:

          set myPath to posix path of ("" & (path to desktop folder) & "New:1.jpg")

          [2] I think the last line of your AS should be something like "return myResult". Then whatever variable you assign the doScript to should get the results you return.
          • 2. Re: How to call applescript values?
            (subha_oviya) Level 1
            Thanks for your reply....
            I need to choose the folder and store it in a variable using applescript...
            This variable need to be passed to javascript and the path has to be returned here..

            i tried this as follows

            var chs="tell application \"finder\"\r";
            chs+="set myPath to file (Choose file with prompt \"Choose\")\r";
            chs+="end tell";

            how to get the value of myPath using javascript...
            Please someone help me....
            i need it urgently
            • 3. Re: How to call applescript values?
              Eric @ MCA Level 3
              You, um, put the results into a variable? Also, like I said in my first post, if you want JS-compatible path, you need to use "posix path of". And finally, I forced it to return as text rather than as a file alias, which is what you were returning initially.

              This script should work:
              var chs="tell application \"finder\"\r";
              chs+="set myPath to (choose file with prompt \"Choose\")\r";
              chs+="set myPath to POSIX path of myPath as text\r"
              chs+="return myPath\r"
              chs+="end tell";
              var myResults = app.doScript(chs,ScriptLanguage.APPLESCRIPT_LANGUAGE);
              alert( myResults );