6 Replies Latest reply on Sep 13, 2009 11:15 PM by FentonJones

    Applescript 'open file' not working in Snow Leopard

    rfwilmut

      Title

      Applescript 'open file' not working in Snow Leopard

      Post

      I've not yet installed Snow Leopard: I understand that the command 'open file' has to be replaced with just 'open' in Snow Leopard/FP10. Does this apply only to Applescripts entered within FP10 scripts, or does it also apply to external scripts where it would be used within 'tell application Finder"'? If the latter, is this a global change in Applescript?

        • 1. Re: Applescript 'open file' not working in Snow Leopard
          TSGal

          rfwilmut:

           

          Thank you for your post.

           

          It appears to be a change in AppleScript.  If you specify the full file name with extension, you need to use "Open".

           

          TSGal

          FileMaker, Inc. 

          • 2. Re: Applescript 'open file' not working in Snow Leopard
            FentonJones
              

            It must not be very global. I am running 10.6.1 and FileMaker 10.0v3. All 3 of the below work; as does the Finder version of them:

             

            -- tell application "FileMaker Pro Advanced" to open "Macintosh HD:Users:fej:Desktop:[t] Increment by 1.fp7"

            -- tell application "FileMaker Pro Advanced" to open alias "Macintosh HD:Users:fej:Desktop:[t] Increment by 1.fp7"

            tell application "FileMaker Pro Advanced" to open file "Macintosh HD:Users:fej:Desktop:[t] Increment by 1.fp7"

             

            So I'm kind of wondering what they are talking about.  It does not work to say:

             

            tellapplication "FileMaker Pro Advanced" toopendatabase "[t] Increment by 1" (or with ".fp7")

            even if it is open. 

             

            I must be missing something. When else would you use "open"? I don't this change would have any effect on the (many) AppleScripts I've written for FileMaker.

            • 3. Re: Applescript 'open file' not working in Snow Leopard
              rfwilmut
                

              My normal syntax in these scripts (these are standalone scripts, not within FMP) would be

               

              tell application "Finder"

              openfile "VT Usage.fp7" offolder "VT Advance bookings" offolder "DATABASES" offolder "Documents" offolder "roger" offolder "Users" ofstartup disk

              end tell 

               

              Does this method work? 

              • 4. Re: Applescript 'open file' not working in Snow Leopard
                FentonJones
                  

                Yes. In fact,

                 

                tell application "Finder"

                open "VT Usage.fp7" of folder "VT Advance bookings" of folder "DATABASES" of folder "Documents" of folder "roger" of folder "Users" of startup disk

                end tell 

                 

                does not work. But this does (providing you haven't changed your hard drive's name, and I reassembled your path correctly):

                 

                tell application "Finder"

                open "Macintosh HD:Users:roger:DATABASES:Documents:VT Advance bookings:VT Usage.fp7" 

                end tell

                 

                 

                Any of these work (for me), in a FileMaker Perform AppleScript step:

                 

                tell app "Finder" to open ((choose file) as text)

                tell app "Finder" to open file ((choose file) as text)

                tell app "Finder" to open (choose file)

                 

                None of the above work in a FileMaker Perform AppleScript step without the "Finder". All of the above work without the Finder in plain AppleScript (outside of FileMaker). 

                 

                So, while I'm sure that this change to only "open" vs. "open file" applies somewhere, I cannot see where. But I don't use "open" all the much within FileMaker (as the file is already open, and the Finder (or System Events) can be used to open others.

                 

                I read somewhere that there has been a change to AppleScript in general, which has to do with the interaction between the Standard Additions Scripting Addition and AppleScript and applications. I didn't completely understand it. It's purpose was to make it all more stable (since Apple has little control over 3rd party Scripting Additions or applications). Perhaps this "open" vs. "open file" change was required by that. Standard Additions contains things like: choose file, list folder, display dialog, read, write (file), etc.. They are not really part of core AppleScript.

                • 5. Re: Applescript 'open file' not working in Snow Leopard
                  rfwilmut
                    

                  Thank you. I was afraid I'd have to go through 40-odd scripts changing the syntax. That'll be one less chore (out of many) when I finally get round to upgrading.

                   

                  I normally use the format I quoted in my previous post, though the path-with-colon-delimiters is necessary if you're saving a file.

                  • 6. Re: Applescript 'open file' not working in Snow Leopard
                    FentonJones
                      

                    Just another little tip. The long path you posted is in a form which you generally only see it in the Finder. There are some (many) AppleScript operations which will not accept that path syntax. But, should you run into this situation, there is an easy way to coerce that syntax to one which is accepted. It is the "as alias" coercion. The following does not work:

                     

                    tell application "Finder"

                    set mac_path to selection

                    -- {folder "zMisc" of folder "Downloads" of folder "fej" of folder "Users" of startup disk of application "Finder"}

                    list folder mac_path without invisibles

                    end tell 

                     

                    But this does:

                     

                    tell application "Finder"

                    set mac_path to selection as alias

                    -- alias "Macintosh HD:Users:fej:Downloads:zMisc:"

                    list folder mac_path without invisibles

                    end tell

                     

                     

                    One last thing :-/

                     

                    Notice the brackets around the 1st path. That is because "selection" can include multiple items, so the result is an AppleScript "list" (not a text list). If you need to work with such, there is another coercion, which works with the Finder (but not outside its block), "as alias list". In the following I have 2 folders selected in the Finder:

                     

                    tell application "Finder"

                    set mac_path to selection as alias list

                    -- {alias "Macintosh HD:Users:fej:Downloads:zDocs:", alias "Macintosh HD:Users:fej:Downloads:zMisc:"}

                    end tell

                     

                    You could them use "repeat" to loop thru these paths, with any AppleScript operation, and process them; or use a find/replace routine to transform them into a text list (return separated).