1 2 Previous Next 23 Replies Latest reply on Feb 26, 2015 12:27 PM by JFWX5

    FM calling AppleScript and trapping for Errors

    JFWX5

      Hi All,



      I’ve been using my ScanSnap with Snap2FM to scan documents in to a container field in my FileMaker solution.


      Here are my steps.


      A) I have a FM script that calls an Applescript to change to the desired scanning profile in ScanSnap for the document type being scanned: i.e. one/two side, Legal, letter, jpeg, pdf, etc


      B) The FM script then changes to the proper layout.


      C) I load the document into the scanner and hit the scanner button, document drops into the FM container!


      All was working great!



      Now that I switched to Yosemite.  Each day the first time I invoke the FM script calling the applescript to change profiles I get



      "System Events got an error: Can’t get window 1 of application process "ScanSnap Manager". Invalid index.”


      with the OK dialog, then I get the FM


      “ unknown Error: -1719”


      with the OK dialog,



      I then have to manually click on the ScanSnap manager, select the profile required and everything works great till the user logs out for the day.


      After a lot of testing I believe that there is something in Yosemite preventing the Applescript from working the first scan of the day, as it had worked flawless under the last two versions of OS X.

       


      The question is how do I trap for the two errors above so that the user is not taken some where they don’t belong?




      Thank you




      John

        • 1. Re: FM calling AppleScript and trapping for Errors
          electon

          Did you try testing the apple script on its own in apple script editor?

          Shouldn't make much difference but the editor can provide a better level of debugging.

          Either something has changed in the Library and the class isn't supported, there's a bug in Yosemite ( they reworked quite a lot of AS )

          or the app isn't fully initialized before the window call.

           

          I'm guessing it's the last one, since it fails only on first run and works after setting stuff manually in the app.

          Try first starting the app manually and then run the FM script. Do you get an error?

          Maybe you're missing an extra script step on top to to initialize the app.

          Kind of difficult to guess without being able to test myself.

          • 2. Re: FM calling AppleScript and trapping for Errors
            JFWX5

            Electon,

             

             

            Try first starting the app manually and then run the FM script. Do you get an error?

             

            NO

             

            Maybe you're missing an extra script step on top to to initialize the app.

             

             

            Here is the Applescript did I fail to initialize?

             

             

            tell application "System Events"

              tell application process "ScanSnap Manager"

              activate

              tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

              click menu item "Settings..."

              end tell

              end tell

            end tell

             

             

             

             

            tell application "System Events"

              tell application process "ScanSnap Manager"

              tell (pop up button 1 of group 2 of window 1)

              click

             

              tell menu 1

              try

              click menu item "FMS"

              end try

             

              end tell

             

              end tell

             

              end tell

             

              tell application "System Events"

              tell application process "ScanSnap Manager"

              -- Apply

              click button "Apply" of window 1

              -- Close

              click button 1 of group 2 of window 1

              end tell

             

              end tell

             

             

             

            end tell

            • 3. Re: FM calling AppleScript and trapping for Errors
              electon

              Oh, the ScanSnap hasn't got a library and you need to manipulate it via system events. I haven't got one so can't test it myself.

               

               

              JFWX5 wrote:


              Try first starting the app manually and then run the FM script. Do you get an error?

               

              NO

               

               

              So if the app is already loaded then no error.

              Try starting the app first then make calls to it. Like this:


              tell application "ScanSnap Manager"

                activate

              end tell

               

              tell application "System Events"

                tell application process "ScanSnap Manager"

                tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                click menu item "Settings..."

                end tell

                end tell

              end tell

               

               

              ------------

              This is just the top of the script. Beyond that I'd have to have the app installed.

              • 4. Re: FM calling AppleScript and trapping for Errors
                JFWX5

                I tried

                 

                tell application "ScanSnap Manager"

                  activate

                end tell

                 

                Still does not work

                • 5. Re: FM calling AppleScript and trapping for Errors
                  sporobolus

                  On 2015-02-25 16:20 , JFWX5 wrote

                  Try first starting the app manually and then run the FM script. Do you get an error?

                   

                  NO

                   

                  if i understand how this email is formatted, you are answering that you do

                  not get an error if Scansnap Manager is started manually before running the

                  script; this would seem to indicate that it just takes a while to start up

                  before it's ready to be controlled via System Events

                   

                  since Scansnap Manager isn't scriptable (i have one and can confirm this)

                  the simplest solution is probably to put a reasonable delay in your script

                  after the activate command (you'll have to experiment to find the amount of

                  delay needed, and you can never be sure this will always work, because a

                  longer delay may be needed if the system is heavily loaded)

                  • 6. Re: FM calling AppleScript and trapping for Errors
                    JFWX5

                    Steve,

                     

                    I tried a delay it did not work

                     

                    Thanks

                    • 7. Re: FM calling AppleScript and trapping for Errors
                      user19752

                      Do you power off and on the scanner each day after logon to the computer?

                      (It is written in Readme of the latest update, sorry the file is Japanese http://www.pfu.jp/downloads/mgr/m-v63l24/MacScanSnapV63L24UpJP_Readme_JP.pdf )

                       

                      Edit:found English version

                      http://origin.pfultd.com/downloads/IMAGE/driver/ss/mgr/m-v63l24/readme_en.pdf

                      • 8. Re: FM calling AppleScript and trapping for Errors
                        nicolai

                        I know it is not the solution, but as a workaround, could you try to suppress the error?

                         

                        try

                             tell application "System Events"

                                    tell application process "ScanSnap Manager"

                                         activate

                                              tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                                              click menu item "Settings..."

                                              end tell

                                         end tell

                             end tell

                        end try


                        You should not be getting pop up and you can modify it to return a flag to FileMaker on error which will indicate it needs to run the same script again.

                        • 9. Re: FM calling AppleScript and trapping for Errors
                          electon

                          Strange thing is that te script runs ok at some point so it seems that the calls to the window are working.

                          Still, I believe the correct method is first to activate the application then make calls to it.

                          If I test your original method on any application that isn't running it fails saying there's no such process.

                          You can't tell an application process to do stuff if there's no such process already running.

                           

                          Only thing I can think of is that the ScanSnap Manager gets loaded at startup as a background process.

                          Try to break your code into smaller chunks and run those watching the screen and debug window of the editor.

                          Quit the Snap Manager between tests.

                          The issue here is an invalid window index, so either the window is missing, you're referring to the wrong window or there's a dialog box when first opening the app that needs dealing with.

                           

                          After the Settings menu gets clicked, try this:

                           

                          tell application "System Events"

                            tell application process "ScanSnap Manager"

                                 tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                                      click menu item "Settings..."

                                 end tell

                           

                          --- check what the window with index 1 is here ---

                          properties of window 1

                          -----------------------------

                            end tell

                          end tell

                           

                           

                          Did you apply the latest ScanSnap update for Yosemite compatibility?

                          • 10. Re: FM calling AppleScript and trapping for Errors
                            JFWX5

                            Nicolai,

                             

                            Said

                             

                            "I know it is not the solution, but as a workaround, could you try to suppress the error?

                             

                            try

                                 tell application "System Events"

                                        tell application process "ScanSnap Manager"

                                             activate

                                                  tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                                                  click menu item "Settings..."

                                                  end tell

                                             end tell

                                 end tell

                            end try


                            You should not be getting pop up and you can modify it to return a flag to FileMaker on error which will indicate it needs to run the same script again."



                            Error keeps coming back over and over till I do a manually scan with program other than FM or simply click on ScanSnap Manager, and click on a profile.


                            Electon Said

                             

                            "After the Settings menu gets clicked, try this:

                             

                            tell application "System Events"

                              tell application process "ScanSnap Manager"

                                   tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                                        click menu item "Settings..."

                                   end tell

                             

                            --- check what the window with index 1 is here ---

                            properties of window 1

                            -----------------------------

                              end tell

                            end tell"

                             

                            Tried this, got the same error in AppleScript

                             

                            error "System Events got an error: Can’t get window 1 of application process \"ScanSnap Manager\". Invalid index." number -1719 from window 1 of application process "ScanSnap Manager"

                             

                            User19752 Said

                             

                            "Do you power off and on the scanner each day after logon to the computer?"

                             

                            Tried that does not work.

                             

                            Based upon the above I would say that properties of window 1, have changed slightly enough to cause the error.

                             

                            I'm not good at this Window location stuff, so maybe I'll just have the a dialog in FM for them to  click on ScanSnap Manager, and click on a profile. So I would still need to trap for this error in case the user does not manually click a profile prior to going opening FM.

                             

                            Thank you



                            • 11. Re: FM calling AppleScript and trapping for Errors
                              nicolai

                              Found this suggestion at Applescript for menu items (error -1719) | Apple Support Communities

                               

                              try to reverse the order

                                  tell application "ScanSnap Manager" to activate

                                        tell application "System Events" to tell process "ScanSnap Manager"

                                                    tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1

                                                    click menu item "Settings..."

                                                    end tell

                                              end tell

                                  end tell

                              • 12. Re: FM calling AppleScript and trapping for Errors
                                JFWX5

                                Nicolai,

                                 

                                Workers are using the computer now, I'll check this out when they go to lunch.

                                 

                                 

                                Thanks

                                • 13. Re: FM calling AppleScript and trapping for Errors
                                  jrenfrew

                                  try UIBrowser from pfiddlesoft.com

                                   

                                  that will help ascertain if you menu item you want is the one you once asked for

                                   

                                   

                                  System Events got an error: Can’t get window 1 of application process...... would indicate that is the problem you need to fix

                                  • 14. Re: FM calling AppleScript and trapping for Errors
                                    electon

                                    nicolai  tell application to activate doesn't need an end tell and will result in compile error.

                                    Also the script errors on referring to the window of index 1 which is further down the line.

                                     

                                    JF, an error from properties of window 1 means that there is no window with such index.

                                    Either the click menu item doesn't open the window the first time or there's a process preventing this.

                                    Do you see the actions carried out / window opening when running the script ?

                                    I would try inserting this

                                    tell application "ScanSnap Manager" to activate

                                    before the call to the window again so it will be "most front" application.

                                     

                                    I'm out of ideas here...

                                    1 2 Previous Next