9 Replies Latest reply on Apr 18, 2015 2:30 PM by zinny

    apple script error help

    zinny

      Title

      apple script error help

      Post

      I have created this applescript to get the duration of a quicktime and insert it into a filemaker field but the apple script doesn't work when I have it decoupled. Mov Files::get path restructured is the filepath with : in place of / and works fine. it's Mov Files::File Name that can't be recognized by the script. the value it returns currently is Reuben_Test_Clip_Prores422.mov

      "tell application \"QuickTime Player\"¶
          open \"" & Mov Files::get path restructured & "\"¶
          tell document \" & Mov Files::File Name & \"¶
              set MovieDuration to the duration¶
          end tell¶
          close document \" & Mov Files::File Name & \"¶
      end tell¶
      tell application \"Finder\"¶
          display dialog \"Movie duration = \" & MovieDuration¶
      end tell¶
      tell application \"FileMaker Pro Advanced\"¶
          set cell \"duration raw\" of current record to MovieDuration¶
      end tell
      "

      Error Message

      Quicktime Player got an error:can't get document

      "Reuben_test_clip_Prores422.mov

      ".

      What am I doing wrong?

      also, how do I trap for Quicktime being open already and the file I want already being open?

       

      Thanks

        • 1. Re: apple script error help
          Jade

          Hi Reuben,

          This is a guess on my part:

          You have correctly escaped the file path with quotes in line 2 and should do the same with the filename in line 3.

          tell document \"" & Mov Files::File Name & "\" …

           

          Jon

          • 2. Re: apple script error help
            FentonJones

            Jade is right, that you need more ", as your moving between the AppleScript and FileMaker fields, without loosing the quote you need.

            As far as looking, and/or opening the "Quicktime Player" application, there is another way to do this; especially if all you need is the "duration" data. First, AppleScript can run Unix commands. There is a Unix command "mdls" (made by Apple) which can get a lot of data about the file. The below is would use such to return the duration. It requires a Unix type file path. The below will be able look at a file in a folder in your user folder.

            -- the 'mdls' command will return all the data it has for the file

            -- do shell script "mdls " & file_unix

             

            -- Duration's line is called by: kMDItemDurationSeconds

            setfile_unixto "~/'" & "Music/iTunes/iTunes Music/Fairport Convention/Liege and Lief/02 Reynardine.m4a'"

            -- "~/'" is "my user path" with a ' then the rest of the file path, with a ' at the end; Unix does not like spaces in file paths otherwise

            setsecstodo shell script "mdls -name kMDItemDurationSeconds " & file_unix-- & " | cut -d = -f 2"

            -- result: " 271.2090702947846"

            -- without the 'cut' command 'mdls' would return the full line: "kMDItemDurationSeconds = 271.2090702947846"

            • 3. Re: apple script error help
              zinny

              Thanks heaps for the answers, I can't get the unix formatting to work for me so that might take a little time, but I found my problem - the calculation I used to get the file name included a return at the end (which is why the error message had the quote on the second line.

               

              I do also want to get some other information out of the quicktime - codec and dimensions (which are both listed under more info in the get info panel). People talk about a applescript dictionary but I can't find the list of values I can pull - does anyone know the magic words to get codec, screen dimensions and audio channels.

               

              Thanks

              • 4. Re: apple script error help
                zinny

                alternatively could I get the 'get info' from right clicking the file as a variable and parse out the info I need from that?

                • 5. Re: apple script error help
                  FentonJones

                  -- codec, screen dimensions and audio channels

                   

                  I don't know much about movie data. The a above type of data is not in a basic "info" from AppleScript (AS) using "get info". It may be in the Unix (run via AppleScript) using "mdls" (metadata). To see if so, use the below:

                   

                  set mac_file to choose file

                  set unix_file to quoted form of POSIX path of mac_file

                  do shell script "mdls " & unix_file

                   

                  Or you may be able to get it from an application such as QuickTime Player (QP). You can see what AppleScript can see in QP, open AppleScript Editor, in the "Window" menu, choose "Library". It will show the built in apps available (likely QP is there); you can add an app to it (if it has AS support). This is what I see for QP:

                   

                  documentn [see also Standard Suite]

                  properties

                  audio volume (real) : The volume of the movie from 0 to 1, where 1 is 100%.

                  current time (real) : The current time of the movie in seconds.

                  data rate (integer, r/o) : The data rate of the movie in bytes per second.

                  data size (integer, r/o) : The data size of the movie in bytes.

                  duration (real, r/o) : The duration of the movie in seconds.

                  looping (boolean) : Is the movie playing in a loop?

                  muted (boolean) : Is the movie muted?

                  natural dimensions (point, r/o) : The natural dimensions of the movie.

                  playing (boolean, r/o) : Is the movie playing?

                  rate (real) : The current rate of the movie.

                  presenting (boolean) : Is the movie presented in full screen?

                  current microphone (audio recording device) : The currently previewing audio device.

                  current camera (video recording device) : The currently previewing video device.

                  current audio compression (audio compression preset) : The current audio compression preset.

                  current movie compression (movie compression preset) : The current movie compression preset.

                  current screen compression (screen compression preset) : The current screen compression preset.

                   

                  Using such will allow you to get the data as text (which is good). However, the not so good is it requires that the file is open with the app (due to "document"); hence you'd have to be sure the app has that file open. This is not that hard to do however. 

                   

                  In my opinion I'd prefer to get the data using "mdls", and try and pull out what I needed; though it may mean pulling it in, then cleaning up the text in FileMaker (which, for me, is much easier to deal with than via Unix commands).

                   

                  It kind of matters whether you need to be "fast", on hundreds/thousands of files, or just one (or a few). In the later case you might prefer to get the data from an app.

                   

                  P.S. I have very few "movie" files. Here is one of them using "mdls":

                   

                  kMDItemAudioBitRate            = 63

                  kMDItemAudioChannelCount       = 1

                  kMDItemCodecs                  = (

                      AAC,

                      "H.264"

                  )

                  kMDItemContentCreationDate     = 2012-04-15 07:55:40 -0700

                  kMDItemContentModificationDate = 2012-04-15 07:55:51 -0700

                  kMDItemContentType             = "com.apple.quicktime-movie"

                  kMDItemContentTypeTree         = (

                      "com.apple.quicktime-movie",

                      "public.movie",

                      "public.audiovisual-content",

                      "public.data",

                      "public.item",

                      "public.content"

                  )

                  kMDItemDisplayName             = "1stbikeride.MOV"

                  kMDItemDurationSeconds         = 10.35833333333333

                  kMDItemEncodingApplications    = (

                      "5.1"

                  )

                  kMDItemFSContentChangeDate     = 2012-04-15 07:55:51 -0700

                  kMDItemFSCreationDate          = 2012-04-15 07:55:40 -0700

                  kMDItemFSCreatorCode           = ""

                  kMDItemFSFinderFlags           = 0

                  kMDItemFSHasCustomIcon         = 0

                  kMDItemFSInvisible             = 0

                  kMDItemFSIsExtensionHidden     = 0

                  kMDItemFSIsStationery          = 0

                  kMDItemFSLabel                 = 0

                  kMDItemFSName                  = "1stbikeride.MOV"

                  kMDItemFSNodeCount             = 0

                  kMDItemFSOwnerGroupID          = 20

                  kMDItemFSOwnerUserID           = 501

                  kMDItemFSSize                  = 1057248

                  kMDItemFSTypeCode              = ""

                  kMDItemKind                    = "QuickTime movie"

                  kMDItemLastUsedDate            = 2012-04-15 07:55:51 -0700

                  kMDItemMediaTypes              = (

                      Sound,

                      Video

                  )

                  kMDItemPixelHeight             = 480

                  kMDItemPixelWidth              = 272

                  kMDItemProfileName             = "HD (1-1-1)"

                  kMDItemStreamable              = 0

                  kMDItemTotalBitRate            = 808

                  kMDItemUsedDates               = (

                      "2012-04-15 00:00:00 -0700"

                  )

                  kMDItemVideoBitRate            = 744

                  • 6. Re: apple script error help
                    FentonJones

                    P.S. I believe that FileMaker 13 has added an ability to get more info from files. I'm still using 12 (as I have on old computer, as I am old). There are also some plug-ins which can see more. I'm not sure which, unfortunately. Hopefully someone with more about this  will come in. If not, then you could ask another question, leaving out the AppleScript, but ask if there are other ways to get this info.

                    • 7. Re: apple script error help
                      zinny

                      Thanks Fenton for this new way - much better than opening quicktime every time and having to error capture over and over. I have managed to get the script working as a native script but when I convert to calculated I start getting a bit lost. I am getting a expected a " here error and I just don't know where I have gone wrong.could you take a look at it with a better understanding of unix and tell me where I have messed up.

                      "
                      set file_unix to \"~/'\" & \"" & Mov Files::File Name path unix & "\'\"¶
                      set codec to do shell script \"mdls -name kMDItemCodecs \" & file_unix -- & \" | cut -d = -f 2\"¶
                      set secs to do shell script \"mdls -name kMDItemDurationSeconds \" & file_unix -- & \" | cut -d = -f 2\"¶
                      set height to do shell script \"mdls -name kMDItemPixelHeight \" & file_unix -- & \" | cut -d = -f 2\"¶
                      set width to do shell script \"mdls -name kMDItemPixelWidth \" & file_unix -- & \" | cut -d = -f 2\"¶
                      tell application \"FileMaker Pro Advanced\"¶
                          set cell \"duration raw\" of current record to secs¶
                          set cell \"screen height\" of current record to height¶
                          set cell \"screen width\" of current record to width¶
                          set cell \"codec\" of current record to codec¶
                      end tell¶
                      "

                       

                      thanks so much if you can give me a little more time

                      • 8. Re: apple script error help
                        FentonJones

                        You are doing very well for a beginner in Unix. I'm no expert myself. About the only real error was that you tried to "protect" the ' , with a \ . ' does not need protection in a FileMaker calculation (like " does). The best way to see what you've got is to create a calculation field (unstored) and put it on the layout. 

                        That brings up another "gotcha" about working with AppleScript from FileMaker. The simplest way of run such lines as:
                        set cell "duration raw" of current record to secs
                        will get an AppleScript error if the cell (field) is NOT on the layout. You could tell AppleScript exactly the path to the table/layout. But generally I find the easiest method is to make sure you are on a layout which has the fields on it (they do not even have to be enterable).

                        Another minor thing is that when running an AppleScript from FileMaker you do not need to use:
                        tell application "FileMaker Pro Advanced"
                        The default of the AppleScript IS FileMaker; it knows itself. Removing that line (and its "End tell" line) also allows people with "FileMaker Pro" to run the script. [ You can also just disable the line, using -- { AS way to do what FileMaker == does; similar (* stuff *) vs. /* stuff */ }.]

                        You disabled the last part of each command in the Unix, by using: -- 
                         | cut -d = -f 2
                        which was running a short command to clean up the data returned. With out it you'd get what 'mdls' returns:
                        kMDItemPixelHeight             = 480
                        What the 'cut' cleans that do is:
                        480
                        Which matters, because it's not only cleaner, but the "screen height" field should be a Number type.

                        [  | cut -d = -f 2 means: continue with another command, 'cut', look (from left) for the character "=", then get what is after it ]

                        Here's your FileMaker's Perform AppleScript calculation cleaned up (a little):
                        "
                        set file_unix to \"~/'\" & \"" & Mov Files::File Name path unix & "'\"¶
                        set codec to do shell script \"mdls -name kMDItemCodecs \" & file_unix & \" | cut -d = -f 2\"¶
                        set secs to do shell script \"mdls -name kMDItemDurationSeconds \" & file_unix & \" | cut -d = -f 2\"¶
                        set height to do shell script \"mdls -name kMDItemPixelHeight \" & file_unix & \" | cut -d = -f 2\"¶
                        set width to do shell script \"mdls -name kMDItemPixelWidth \" & file_unix & \" | cut -d = -f 2\"¶
                        set cell \"duration raw\" of current record to secs¶
                        set cell \"screen height\" of current record to height¶
                        set cell \"screen width\" of current record to width¶
                        set cell \"codec\" of current record to codec
                        "

                        P.S. "File Name path unix" would be better as: File_path_unix [ it is not really "name", and you might want a "File_name" ]

                        P.S.S. "One more thing" :-}  "codec" can return multiple values. For example:
                         (
                            AAC,
                            "H.264"
                        )
                        Unless you know more Unix that I do :-, I'd clean this up after AS is done, using FileMaker's function:
                        Substitute ( codec ; ["(¶"; ""]; ["¶)"; ""]; ["\""; ""]; ["    "; ""]; [","; ""] )
                        It could be an Auto-enter Calculation, with [  ] Do not replace existing value of field { disabled }
                        AAC
                        H.264
                        [ or similar, or remove one of them; I don't really know ]

                        LAST thing; previously I gave this as a Unix example:

                        set file_unix to "~/'" & "Music/iTunes/iTunes Music/Fairport Convention/Liege and Lief/02 Reynardine.m4a'"

                        -- "~/'" is "my user path" with a ' then the rest of the file path, with a ' at the end; Unix does not like spaces in file paths otherwise

                        The main thing to notice is that I'm only giving the path from the 1st folder of the path, from MY user folder. I am not giving a full path to the computer system, nor even the User's folder. You could however not use "~/", and give it a full Unix path instead (which is similar to what a FileMaker path would look like; but you'd need to remove some of the left, and still use the ' as FileMaker allows spaces in paths, Unix does not.

                        • 9. Re: apple script error help
                          zinny

                          Thank you so much for all your time - it works a treat! I havent been able to find a good explanation of formatting apple scripts for calculation so all your tips are appreciated heaps.