23 Replies Latest reply on Mar 25, 2016 12:09 PM by Laubender

    Get name of startup disk JS

    penyfai Level 1

      I've got an applescript that get's the name of the startup disk using

       

      set macname to get name of startup disk

       

      I'm wondering if the same can be done in a javascript that runs in InDesign CS3....

       

      I need to make the scripts work across platforms and am new to Java Scripting.

       

      Thanks in advance for any feedback.....

        • 1. Re: Get name of startup disk JS
          Peter Kahrel Adobe Community Professional & MVP

          Folder.system and Folder.startup are probably the properties you need. You can read about themn in JavaScript Tools Guide CS3.pdf, available in the ESTK's Help menu.

           

          Peter

          • 2. Re: Get name of startup disk JS
            Kasyan Servetsky Level 5

            Folder.system and Folder.startup

            No, these properties don't help:

             

            startupFolderreadonlyA Folder object for the folder containing the executable image of the  running application.
            systemFolderreadonly

            A Folder object for the folder containing the operating  system files.

            In Windows, the value of %windir% (by default, C:\\Windows) In Mac OS,  /System

            • 3. Re: Get name of startup disk JS
              Peter Kahrel Adobe Community Professional & MVP

              Well, on Windows, Folder.system returns /c/WINDOWS/SYSTEM32. So this:

               

              String (Folder.system).charAt(1)

               

              returns C. But maybe I don't understand what the OP means by "start-up disk". Anyway, digging into that Tools Guide pdf should make things clear to him.

               

              Peter

              • 4. Re: Get name of startup disk JS
                Kasyan Servetsky Level 5

                On Mac OS, I get:

                 

                Folder.startup;

                /Applications/Adobe%20InDesign%20CS3/Adobe%20InDesign%20CS3.app/Contents/MacOS

                 

                and

                 

                Folder.system;

                /System

                 

                I don't see a straightforward way to get it so far.

                 

                Kasyan

                • 5. Re: Get name of startup disk JS
                  Kasyan Servetsky Level 5

                  var myDisk = GetStartUpDisk();
                  alert("The name of my start up disk is \"" + myDisk + "\"");

                   

                  function GetStartUpDisk() {
                      if (File.fs == "Macintosh") {
                          var myScript = 'tell application \"Finder\"\r'
                          myScript += 'set myStartUpDisk to get name of startup disk\r';
                          myScript += 'end tell\r';
                          myScript += 'tell application \"Adobe InDesign CS' + ((parseInt(app.version.substr(0, 1)) - 2) + "") + '\"\r';
                          myScript += 'tell script args\r';
                          myScript += 'set value name \"myScriptArgument\" value myStartUpDisk\r';
                          myScript += 'end tell\r';
                          myScript += 'end tell\r';
                          app.doScript(myScript, ScriptLanguage.applescriptLanguage);
                          var myStartUpDisk = app.scriptArgs.getValue("myScriptArgument");
                      }
                      else if (File.fs == "Windows")  {
                          var myStartUpDisk = String(Folder.system).charAt(1);
                      }
                      return myStartUpDisk;
                  }

                  • 6. Re: Get name of startup disk JS
                    penyfai Level 1

                    Thanks Peter and Kasyan.

                     

                    As I said I'm a newbie to JavaScripting, but I can see what you're both saying (I think). It was far more straight forward in AS.

                     

                    I take it I need a subfunction to get the name of the startup disk on Mac but on the PC I can use String (Folder.system).charAt(1).

                     

                    I was wondering if it is easier to use the ~ to get to the root of the user.

                     

                    So if I was trying to navigate to volumes I'd use ~/volumes/mounteddisk/dir/etc.

                     

                    Does this make sense? I tried to add this to a variable but it doesn't work, so I thought of hard coding it. Not the best solution, but workable...

                     

                    Many thanks again for the feedback.....

                    • 7. Re: Get name of startup disk JS
                      Dirk Becker  Level 4

                      "~" is your home directory, equivalent to "/Users/yourLoginName" .

                      Absolute paths start with a "/" slash.

                       

                      To see yourself, find and run Terminal.app in /Applications/Utilities.

                      Drag any file or folder to the terminal, and you see the full path.

                       

                      Problem with OSX is that the volume name of the boot volume is irrelevant (the system volume is always "/" ) so it is not available from that Folder.system.

                      Dirk
                      • 8. Re: Get name of startup disk JS
                        Steven.. Level 3

                        If it's easily done with AppleScript then why don't you run AppleScript with doScript and store result and return to your javaScript. Good luck

                        • 9. Re: Get name of startup disk JS
                          Kasyan Servetsky Level 5

                           

                           

                          In post #5 I posted a ready to use function that returns the name of start up disk and works both on Mac and Windows. It should work on CS2, 3 and 4, although I tested it only on CS3. You just have to copy it and paste into your script.

                           

                          Kasyan

                          • 10. Re: Get name of startup disk JS
                            penyfai Level 1

                            Hi Kasyan

                             

                            Sorry I haven't replied through the forum - as a system support engineer I

                            have to fit projects into our day to day work, and since Friday I've been

                            unable to make further progress. I really appreciate all of the help that

                            the forum presents and will add your solution to my script as soon as

                            possible.

                             

                            I will update the thread as soon as possible - you've actually helped me a

                            few times in the past too, so many thanks once again...

                             

                            Andrew

                             

                             

                            Wales is just a click away - http://www.walesOnline.co.uk - news, sport, culture and entertainment

                             

                            IMPORTANT NOTICE This email (including any attachments) is meant only for the intended recipient. It may also contain confidential and privileged information. If you are not the intended recipient, any reliance on, use, disclosure, distribution or copying of this email or attachments is strictly prohibited. Please notify the sender immediately by email if you have received this message by mistake and delete the email and all attachments.

                             

                            Any views or opinions in this email are solely those of the author and do not necessarily represent those of Trinity Mirror PLC or its associated group companies (hereinafter referred to as "TM Group"). TM Group accept no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Although every reasonable effort is made to keep its network free from viruses, TM Group accept no liability for any virus transmitted by this email or any attachments and the recipient should use up-to-date virus checking software. Email to or from this address may be subject to interception or monitoring for operational reasons or for lawful business practices.

                             

                            Trinity Mirror PLC is the parent company of the Trinity Mirror group of companies and is registered in England No 82548, with its address at One Canada Square, Canary Wharf, London E14 5AP.

                             

                            • 11. Re: Get name of startup disk JS
                              Muppet Mark-QAl63s Level 4

                              I may be a mile out here with what you want but being mac only I've been using this:

                               

                              #target indesign

                               

                              var thisOS = $.os;

                              alert(thisOS);

                               

                              var usersHome = Folder('~').fsName.toString();

                              alert(usersHome);

                              • 12. Re: Get name of startup disk JS
                                penyfai Level 1

                                Kasyan

                                 

                                Absolutely brilliant.

                                 

                                As stated previously, I don't get much time to put aside to this project, so sorry for not testing previously. I don't want to upset everyone on the forum by ignoring their input.

                                 

                                I'll work my way through this code and see if I can learn from it.

                                 

                                Cheers again

                                Andrew

                                • 13. Re: Get name of startup disk JS
                                  Laubender Adobe Community Professional & MVP

                                  Hi Kasyan!


                                  This is a very old thread, but I came accross it while searching for a solution to put the name of my startup disk in front of a file path in the "ancient" notation where the folder hierarchy is represented with a ":" devider istead of the "/".

                                   

                                  For all lurkers here:

                                  When exporting to fixed layout EPUB using the epubFixedLayoutExportPreferences in InDesign CC 2014, you sometimes need this "ancient" notation when working on a Mac. In the epubFixedLayoutExportPreferences you can assign an array of file paths to external CSS and JS files. And these file paths are in the notation:


                                   

                                  "NameOfTheDisk:NameOfFolder:NameOfOtherFolder:external.css"

                                   


                                  Instead of:

                                   

                                  "/NameOfFolder/NameOfOtherFolder/external.css"

                                   

                                   

                                  If you do the folder devider with "/" and the root is simply written as a "/" at start of the file path, the export will fail to include the external CSS and JS files.

                                  See this thread in the Adobe InDesign EPUB Forum for example:

                                  Script EPUB export not including JS/CSS with epubFixedLayoutExportPreferences

                                   

                                  So let me thank you for this AppleScript snippet to get the name of the startup disk!!!

                                   

                                  I have added some lines of code to get the name of the InDesign app more accurately equal of its version number.

                                  I've tested this on my MacBook with OSX 10.7.5. Hope, that the AppleScript part will not break on later instances of Mac OSX.

                                   

                                  Here your code with my small addition:

                                   

                                  //Kasyan Servetsky
                                  //https://forums.adobe.com/message/2336686#2336686
                                  
                                  //Some small addition by Uwe Laubender
                                  
                                  var myDisk = GetStartUpDisk();
                                  $.writeln("The name of my start up disk is: \"" + myDisk + "\"");
                                  
                                  function GetStartUpDisk() {
                                      
                                      //Get the name of the application for Mac users:
                                      var myAppName = decodeURI(File(app.fullName).name).replace(/\.app$/,"");
                                      
                                      if (File.fs == "Macintosh") {
                                          var myScript = 'tell application \"Finder\"\r'
                                          myScript += 'set myStartUpDisk to get name of startup disk\r';
                                          myScript += 'end tell\r';
                                          
                                          /* CHANGED LINE: I replaced the original line (now commented out) with a more general approach */
                                          /* myScript += 'tell application \"Adobe InDesign CS' + ((parseInt(app.version.substr(0, 1)) - 2) + "") + '\"\r'; */    
                                          myScript += 'tell application \"'+myAppName+'\"\r';
                                          
                                          myScript += 'tell script args\r';
                                          myScript += 'set value name \"myScriptArgument\" value myStartUpDisk\r';
                                          myScript += 'end tell\r';
                                          myScript += 'end tell\r';
                                          app.doScript(myScript, ScriptLanguage.applescriptLanguage);
                                          var myStartUpDisk = app.scriptArgs.getValue("myScriptArgument");
                                          }
                                      
                                      else if (File.fs == "Windows")  {
                                          var myStartUpDisk = String(Folder.system).charAt(1);
                                          }
                                      
                                      return myStartUpDisk;
                                  }
                                  

                                   

                                  Hm, now the question is: How can I get the name of a disk, that is not the startup disk?
                                  Could one of the AppleScripters here in the forum comment on that?

                                   

                                  All the best to you, Kasyan!

                                   

                                  Uwe

                                  • 14. Re: Get name of startup disk JS
                                    Loic.Aigon Adobe Community Professional

                                    Hi all,

                                     

                                    For what it's worth, I wrote a blog post on this topic a while ago : http://www.ozalto.com/add-custom-indesign-variables/

                                     

                                    Loic

                                    http://www.ozalto.com

                                    • 15. Re: Get name of startup disk JS
                                      Laubender Adobe Community Professional & MVP

                                      Thank you Loic for sharing this…

                                      I will make good use of the design pattern of your script!

                                       

                                      Now I will do a little research in AppleScript to get the right method for the volume's name of a given file or a folder.

                                       

                                      Uwe

                                      • 16. Re: Get name of startup disk JS
                                        Kasyan Servetsky Level 5

                                        Hi Uwe,

                                        I am sorry for the late reply: I was able to get to my Mac only today.

                                        Here's a snippet of code to give you idea of how to get folder's/file's disk name:

                                        theVolumeName.png

                                        Regards,
                                        Kasyan

                                        • 17. Re: Get name of startup disk JS
                                          Laubender Adobe Community Professional & MVP

                                          Hi Kasyan!
                                          Thank you very much for sharing this.

                                           

                                          Yesterday I read a bit in Apple's documentation of AppleScript.
                                          About file and file aliases and getting access to existing files through it.

                                           

                                          But I had no time testing anything.
                                          So your code snippet is more than welcome!!I

                                           

                                          How would implement this?
                                          As I see it the user is prompted for a folder with: "to choose folder", isn't it?
                                          I will test it myself… No need disturbing you more than necessary…
                                          Again, thank you.

                                           

                                          Also, I ran accross a rather lengthy thread in the AppleScript forum of hilfdirselbst.ch (German language):
                                          "Get name of file path in AppleScript"

                                          Dateipfad via Apple-Script abfragen - AppleScript - HilfDirSelbst.ch - Forum

                                           

                                          That discussion is revolving around getting the name of any mounted device. Equal of network protocol and used devices.

                                          Let's see what I can "distill" out of it.

                                           

                                          Uwe

                                          • 18. Re: Get name of startup disk JS
                                            Kasyan Servetsky Level 5

                                            Uwe,

                                             

                                            Choosing a folder isn't a must: you can use a folder path. I just showed you my approach.

                                            I'm not an expert in AS and I think the last time I used it was a couple of years ago. To solve AS issues quickly I use Script Debugger in debugging mode: set variables, copy-paste them into the expression field so I could watch their current values. Double-clicking a variables there opens a separate window with all the properties and their current values — a sort of "Data Browser" for AS. Very handy!

                                             

                                            — Kas

                                            • 19. Re: Get name of startup disk JS
                                              Dirk Becker Level 4

                                              Here some short snippets:

                                               

                                              app.doScript('tell application "Finder" to get name of startup disk',ScriptLanguage.APPLESCRIPT_LANGUAGE);
                                              Ergebnis: Yosemite
                                              app.doScript('tell application "Finder" to get Posix file (item 1 of arguments) as text',ScriptLanguage.APPLESCRIPT_LANGUAGE,[Folder("~/Desktop").fsName]);
                                              Ergebnis: Yosemite:Users:dirk:Desktop:
                                              

                                               

                                              Hth,

                                              Dirk

                                              • 20. Re: Get name of startup disk JS
                                                Laubender Adobe Community Professional & MVP

                                                Hi Dirk!
                                                Cool. Exactly what I need!
                                                Just tested…

                                                 

                                                Thank you very much!
                                                Uwe

                                                • 21. Re: Get name of startup disk JS
                                                  Harbs. Level 6

                                                  Hey guys, it is definitely possible to get the startup volume name in ExtendScript:

                                                   

                                                  var root = File("/").parent.displayName;

                                                  alert(root);

                                                  • 22. Re: Get name of startup disk JS
                                                    Laubender Adobe Community Professional & MVP

                                                    Hah!

                                                    The parent of the root* "/"…

                                                     

                                                    Harbs, you are the best!
                                                    Thank you!

                                                     

                                                    Uwe

                                                     

                                                    * at least, I thought it was the root ;-)

                                                    • 23. Re: Get name of startup disk JS
                                                      Laubender Adobe Community Professional & MVP

                                                      Hi Harbs,

                                                      recently I realised that on OSX (maybe also on Windows?) any valid path string in
                                                      File("AnyValidPathString").parent.displayName will return the volume name of that path.

                                                       

                                                      So we have a method to find out the volume's name if using selectDialog() of object Folder if it will return a valid path object.

                                                      And we can compare it to the name of our startup disk, if we want to. Looking for fsName on the returned path will reveal, if it's the startup disk or not. So we can discern two volumes with the same name and find out the startup one.

                                                       

                                                      But can we find out what path of what disk is returned with selectDialog(), if there are two or more volumes mounted, that share the same name?
                                                      Use case: Two USB sticks are plugged with the same name—"INTENSO"—and the user is selecting a path on one of the sticks by answering the selectDialog() method.


                                                      How can we know what exact volume is accessed when using that path string?


                                                      I guess in this case we should always do a reference to the returned Folder object of selectDialog() not to confuse the two volumes.
                                                      Using the string of the path to construct a new Folder object would maybe lead to the wrong volume.

                                                       

                                                      Hm…
                                                      Something to test…

                                                       

                                                      Uwe