Friday, August 22, 2014

#1 2012-11-21 09:11:44 am

MitchBVI
Member
Registered: 2006-02-14
Posts: 110

Change in Gui Commands

Just switched to Mountain Lion and a script that used to process emails no longer works. I have a handler as part of the routine that saves the message as a PDF file .

I extracted the handler as a standalone script and opened an email and ran it. The print dialog box opens and then it hangs telling "Sheet1 of Windows 1 of process "Mail" is false. As the dialog is open that does not make sense unless the object descriptions are incorrect.

This is the script any help greatly appreciated.

Applescript:

tell application "System Events"
   tell process "Mail"
       keystroke "p" using command down
       repeat until exists sheet 1 of window 1
           delay 0.2
       end repeat
       tell sheet 1 of window 1
           click menu button "PDF"
           repeat until exists menu 1 of menu button "PDF"
               delay 0.02
           end repeat
           click menu item "Save as PDF…" of menu 1 of menu button "PDF"
       end tell
   end tell
end tell

Peter

Model: iMac 27
AppleScript: 2.5(138)
Browser: Safari 536.26.14
Operating System: Mac OS X (10.8)

Offline

 

#2 2012-11-21 03:17:13 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 110

Re: Change in Gui Commands

Fixed that problem with tell block to call mail first. Now I cannot get GUI to select a menu item.
This is the handler I I included the error message below the call that causes the problem.

Applescript:

on FileasPDF()
   tell application "Mail"
       activate
   end tell
   tell application "System Events"
       tell process "Mail"
           keystroke "p" using command down
           repeat until exists sheet 1 of window 1
               delay 0.2
           end repeat
           display dialog "Exists sheet1 of window 1"
           tell sheet 1 of window 1
               click menu button "PDF"
               repeat until exists menu 1 of menu button "PDF"
                   delay 0.02
               end repeat
               display dialog "Exists menu 1 of menu button PDF"
               
               click menu item "Save as PDF…" of menu 1 of menu button "PDF"
               --error "System Events got an error: Can’t get menu 1 of menu button \"PDF\" of sheet 1 of window 1 of process \"Mail\". Invalid index." number -1719 from menu 1 of menu button "PDF" of sheet 1 of window 1 of process "Mail"
               
           end tell
           repeat until exists window "Save"
               delay 0.2
           end repeat
           tell window "Save"
               keystroke "g" using {command down, shift down}
               repeat until exists sheet 1
                   delay 0.2
               end repeat
               tell sheet 1
                   --Subject_Added Peter to test how to pass file name
                   set value of text field 1 to POSIX path of destinationFolder & "/" & Subject_
                   click button "Go"
               end tell
               repeat while exists sheet 1
                   delay 0.2
               end repeat
               click button "Save"
           end tell
       end tell
   end tell
end FileasPDF

Any suggestions please.

Peter

Offline

 

#3 2012-11-21 03:40:17 pm

regulus6633
Member
From: Taulov, Denmark
Registered: 2006-11-01
Posts: 1695
Website

Re: Change in Gui Commands

Just get rid of your "display dialog" commands. They are taking focus away from the objects you want to click and thus causing the error.

Offline

 

#4 2012-11-22 07:59:07 am

MitchBVI
Member
Registered: 2006-02-14
Posts: 110

Re: Change in Gui Commands

Hi Hank

Thanks for the advice I had put them in to debug the first problem the moment I commented them out it worked as you suggested but only down to the next repeat. It cannot see the Window "Save" I have tried "Save As" and Save As:". As I mentioned in my earlier post this whole routine was working fine before the upgrade to Mountain Lion so I wonder if the names of the windows have changed.

Thanks you again any ideas would be appreciated.

Peter

Offline

 

#5 2012-11-22 08:19:09 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1426

Re: Change in Gui Commands

MitchBVI wrote:

Hi Hank

It cannot see the Window "Save" I have tried "Save As" and Save As:". .

Peter

I guess that it would behave correctly if you use the correct item name which is : "Save As…"  (Yes, the ellipsis character).

Yvan KOENIG (VALLAURIS, France) jeudi 22 novembre 2012 15:18:14

Offline

 

#6 2012-11-22 08:31:43 am

MitchBVI
Member
Registered: 2006-02-14
Posts: 110

Re: Change in Gui Commands

Hi Yvan

Thanks for the reply tried that and it did not help. It is the window/sheet not sure which I need to address. You may have noticed earlier in the routine I used "Save As PDF..." which then opens the save window and it is on that window I want to Activate the "Save" button but first I need the routine to recognize that the Save window is open".
I have tried to determine the name of the save window but  all the command below  returns is the name of the window that the "Save as PDF..." was called from.

Applescript:

tell application "System Events" to get the title of every window of process "Mail"

Thanks again

Peter

Offline

 

#7 2012-11-22 09:00:44 am

regulus6633
Member
From: Taulov, Denmark
Registered: 2006-11-01
Posts: 1695
Website

Re: Change in Gui Commands

They are all sheets now so you can't be telling any "window". Try this...

Applescript:

on FileasPDF()
   tell application "Mail"
       activate
   end tell
   tell application "System Events"
       tell process "Mail"
           keystroke "p" using command down
           repeat until exists sheet 1 of window 1
               delay 0.2
           end repeat
           
           tell sheet 1 of window 1
               click menu button "PDF"
               repeat until exists menu 1 of menu button "PDF"
                   delay 0.02
               end repeat
               
               click menu item "Save as PDF…" of menu 1 of menu button "PDF"
               
           end tell
           
           repeat until exists (sheet 1 of sheet 1 of window 1)
               delay 0.2
           end repeat
           
           keystroke "g" using {command down, shift down}
           repeat until exists sheet 1 of sheet 1 of sheet 1 of window 1
               delay 0.2
           end repeat
           
           tell sheet 1 of sheet 1 of sheet 1 of window 1
               set value of text field 1 to POSIX path of (destinationFolder & "/" & Subject_)
               click button "Go"
           end tell
           
           repeat while exists sheet 1 of sheet 1 of sheet 1 of window 1
               delay 0.2
           end repeat
           
           tell sheet 1 of sheet 1 of window 1
               click button "Save"
           end tell
       end tell
   end tell
end FileasPDF

Offline

 

#8 2012-11-22 01:08:10 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 110

Re: Change in Gui Commands

Hi

Cannot thank you enough smile one minor change I no longer need the POSIX path, changed that and  the whole scrip is now working again, at least I hope so.

Peter

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.029 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)