4 Replies Latest reply: May 31, 2012 1:19 PM by davidbread
davidbread Level 1 Level 1 (0 points)

Hi guys

 

Leopard 10.5.8, intel

 

My code is copying one Excel cell at a time and storing as a variable (always called typistSomething). Then it flips to a Safari window and enters all the variables quickly, one after the other. All is well, I am just having problems with changing pop up buttons! I've paired down my code to try to work on the problem area. In the following example, you have to imagine that I've just copied a media type (say, "Movie") to the clipboard, then the pop up button I get to needs to be changed to "Movie" from its default blank state. I don't think I can 'set' a pop up button like I'm trying to. Here goes:

 

 

set typistType to «class ktxt» of ((the clipboard as text) as record)

 

--enter type to Entry Form

activate application "Safari"

tell application "System Events"

          tell process "Safari"

                    set pop up button "Please select the type of video file" of group 6 of UI element 1 of scroll area 1 of group 1 of UI element 1 of scroll area 1 of group 1 of window "Video Metadata" to keystroke typistType

          end tell

end tell

 

 

You see, I might be getting mixed up with 'keystroke' instruction, and just 'setting' it. I have highlighted the name of the field in dark red just to separate it from my bad bits. I'm afraid I'm a real beginner with this. What do you think? I've looked at the pop up button in UI Browser, and if I hover over the selection I want then it tells me, amongst other things, menu item "Movie" (menu item 5).

Thank you

David


MacBook Pro, Mac OS X (10.5.8), Applescript, pop up button
  • Pierre L. Level 5 Level 5 (4,140 points)

    Just in case it might help, here's an example of how you can change the value of the "View" pop up button in this page.

     

    tell application "Safari" to activate

    tell application "System Events"

        tell process "Safari"

            set thePopUpButton to pop up button 1 of group 34 of UI element 1 of scroll area 1 of group 1 of group 1 of group 3 of window 1

            if value of thePopUpButton is not "Only notes" then

                click thePopUpButton

                keystroke "Only notes" & return

            end if

        end tell

    end tell


    Message was edited by: Pierre L.

  • davidbread Level 1 Level 1 (0 points)

    Pierre, thank you so much for your help - this works and I'm very enthusiastic.

     

    There is one small problem, and that is delay. After click thePopUpButton, and before the keystroke that sets it, there is a delay of between 4 and 5 seconds. Really weird. What do you think this could be? I've tried changing simple stuff.... like I tried getting rid of the if, and changed the keystroke from a fixed value to a variable (based on clipboard) but it's always the same.

     

    Again, thank you. Even with a delay, this means the script can be made bombproof, and therefore safe to leave going for long periods of time. Really good.

    Thanks

    David

  • Pierre L. Level 5 Level 5 (4,140 points)

    All I can say is that there's no delay when I run the previous script on my MacBook Pro 2.66 GHz (mid-2010) under Mac OS X 10.7.4. I really don't know where that delay might come from.

     

    By the way, “group 34” should now be replaced with “group 36” in the script. To find out the exact reference to the pop up button, just use the following statement:

    return pop up buttons of groups of UI elements of scroll areas of groups of groups of groups of window 1

     

    Message was edited by: Pierre L.

  • davidbread Level 1 Level 1 (0 points)

    Thanks, Pierre.

     

    I am testing this on two machines, but they're both 2007 Intels, both running Leopard. I will look into upgrading my personal machine... it's something I really ought to do anyway.

     

    Thanks again.