5 Replies Latest reply on May 24, 2016 5:22 AM by Trevorׅ

    Help Needed!

    natrev Level 3

      Hi EveryOne!


      Please fix the below mentioned code. I'm try lot but I can't.

      Help much appreciated.




      var filePath=File("~/Desktop/Test.tif");
      function ChangeLabelColor(filePath){
          var myAppleScript = 'tell application "Finder"\r'
          myAppleScript +='set label index of file (POSIX file \"'+filePath+'\") to 2\r';  
          myAppleScript += 'end tell\r';  
          var SysName =app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);  
        • 1. Re: Help Needed!
          tpk1982 Level 4
          1 person found this helpful
          • 2. Re: Help Needed!
            Trevorׅ Adobe Community Professional

            Are there any Unicode characters in the file path?

            If so that could mess things up and you have to pass them to the applescript diferently.

            • 3. Re: Help Needed!
              Trevorׅ Adobe Community Professional

              I think you have to pass the fsName and not the file name

              • 4. Re: Help Needed!
                S Hopkins Adobe Community Professional

                You need to use the arguments parameter of doString to pass in a reference to the file.

                The problem is in getting the path to the user's desktop to translate inside of the doScript script.

                One solution would be to pass the name of the file, and add it to the user's desktop folder path as defined inside of the doScript.

                var myParameters = ["Test.tif"];

                var myAppleScript = "tell application \"Finder\"\r";

                myAppleScript +='set myFileName to item 1 of arguments\r';

                myAppleScript += 'set myFile to (path to desktop from user domain) as string  & item 1 of arguments\r'

                myAppleScript +='set label index of file ( myFile ) to 2\r';  

                myAppleScript += "end tell";

                app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage, myParameters);


                Hope this helps. I will be discussing the topic of using the arguments parameter in doScript with this week's blog if you are interested (yourscriptdoctor.com/blogs)

                1 person found this helpful
                • 5. Re: Help Needed!
                  Trevorׅ Adobe Community Professional

                  Glad to have helped.


                  Just for the record if one does need to pass a Unicode file name or string to applescript then sending the fsName as is will not work.

                  The applescript processor will receive it in the form of <0068><0054><006C><006C><006F> and would set the file name to just that "<0068><0054><006C><006C><006F>".

                  Parsing in the form of 'string id {104, 101, 108, 108, 111}' would be nice and easy but has it's problems so I think the most solid form of passing is as ' «data utxt0068» as Unicode text & «data utxt0065» as Unicode text & «data utxt006c» as Unicode text & «data utxt006c» as Unicode text & «data utxt006f» as Unicode text'


                  This can be easily done with the below function.

                  I gather it's a bit off the topic but...


                  // Pass Unicode to from extended to applescript
                  // https://forums.adobe.com/message/8766723?et=watches.email.outcome#8766723
                  // by Trevor http://creative-scripts.com/
                  function toAppleUnicode(s) {
                      var a, n, l, unicode;
                      a = [];
                      l = s.length;
                      for (n = 0; n < l; n++) {
                          unicode = ("0000" + (s.charCodeAt(n).toString(16))).slice(-4);
                          a[n] = '\u00abdata utxt' + unicode + '\u00bb as Unicode text';
                      return a.join(' & ');
                  var myApplescript, result;
                  myApplescript = toAppleUnicode("\uD83D\uDE03 hello   ");
                  result = app.doScript(myApplescript, ScriptLanguage.APPLESCRIPT_LANGUAGE);
                  alert('\nresult: ' + result + '\nmyApplescript: ' + myApplescript);


                  P.s. Nice blog, Doctor, probably the best resources for learning apple-scripting for inDesign that exists in particular your practice of writing all the snippets in both applescript and extendedscript