How to use Automator to bring window to front?

天涯浪子 提交于 2019-12-21 20:16:08

问题


I'm using a Mac, OSX 10.6 and I have a function in a desktop application that I want to automate. Manually I press Command+R wait for the application to read some data form a physical device for 1 minute, then press command+R again to take another reading (at this point it asks me if I want to save the data, so I press tab, tab and then space bar to select to save the data. I do this 3 times in total, so I want to automate the 3 times, so I can walk away from the computer and it will read 3 times automatically.

Is automator the best way to do this?

I've tried to do this already in automator by using the 'watch me do' function. This starts with the 'bring window Untitled to the front', and then the second command is press command+R. I then found a little piece of apple script to wait 1 minute and I plug the first action into that for the wait function.

However, when I click run or step, instead of going and opening up the correct window ("Untitled"), the cursor moves to the Media button in automator, and clicks that instead! But the application is definitely listed as the correct one.

Any help appreciated, but maybe automator is the wrong way to go?


回答1:


Apple Script is the best way to go for things that don't require any "special processing" that would need to be done by a chain of different applications.

1) uging the AppleScript Utility make sure that you have GUI scripting enabled in the "AppleScript Utility" 2) using the Script Editor choose File>Open Library and see if your application has any scriptable functions ... these may be a better way to go.

3) Create a new script and put in something like this ...

tell application "Firefox"
    activate
    delay 1 -- give it time to react

    repeat 3 times
        -- this gives us the keyboard
        tell application "System Events" 
            keystroke "r" using {command down}
        end tell
        delay 6
    end repeat
end tell

I used Firefox to test it .... should work for you ....

Once you've got the script you can use the save as to make it into an app or save it as a script in your ~/Library/Scripts folder or paste it into an automator workflow and schedule it with iCal.




回答2:


I don't think automator is the way to go. You could use applescript, but you should take a look at sikuli. You will need to write the Sikuli script yourself, but what you describe shouldn't be difficult



来源:https://stackoverflow.com/questions/2262841/how-to-use-automator-to-bring-window-to-front

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!