自动测试的崛起!

mac 机怎么实现自动截取当前窗口?

上一篇 / 下一篇  2010-07-08 23:35:03 / 个人分类:MAC Testing

  最近在研究MAC上的自动截图方法。 自学了applescript,当然不是很精通的那种学习。但是久久困于怎么实现自动截取当前窗口的函数研究。试过几种方法,在网上也都查过,不过都是无果而终。 前些天,想出个方法,就是在用system events 模拟执行Contrl+shift+4+space后,用automator 录制一个点击动作(用system events的click方法老是点不到当前窗口上)。  这个方法单单从单个语言的系统上跑脚本还算可以,但是一旦切换语言,就原形毕露了。用automator录制的click的动作,老是报错。。所以我又陷入的谜团中。。
 
  希望MAC的自动高手给小弟指点迷津,感激不尽。。。
 
 
终于在国外的论坛找到答案,希望给他家一个启示。。
 
You might have options using your Mac's own built-in Speech Recognition framework.

The following example scripts are designed to perform. the indicated click-actions via spoken command when your mouse cursor is already situated at a desired spot -- hovering over a piece of text, a link, an application icon, a folder, empty space on the desktop, etc. Moving your cursor to the particular spot is another matter. According to the information found onthis page, under 'Make Your Move,'however, it would seem that Dictate does allow you to move the cursor via voice. My hope would be that you can use the scripts below in conjunction with Dictate.

Paste each of the following blocks of code into your AppleScript. Script. Editor. In each case, choose File > Save As > File Format: application, and leave the Options unchecked. Place aliases for the saved scripts into your Home > Library > Speech > Speakable Items folder:

1) This script. performs a single-click, good for clicking links. When saving, you can name it "Click." The code:

tell application "System Events"
keystroke tab using command down
keystroke (ASCII character 53)
end tell

2) This one performs a double-click, good for opening applications or folders, and for those occasions when you want to highlight a single word on a page. Name it "Double Click."

tell application "System Events"
keystroke (ASCII character 53)
keystroke (ASCII character 53)
end tell

3) Likewise, triple-click, for highlighting a line or an entire paragraph of text. Name this one "Triple Click."

tell application "System Events"
keystroke (ASCII character 53)
keystroke (ASCII character 53)
keystroke (ASCII character 53)
end tell

4) This script. performs a control-click (right-click) on an item or on a piece of text, useful when you want to bring up a contextual menu. Name it "Control-Click" (or "Right-Click").

tell application "System Events"
keystroke tab using command down
key down control
keystroke (ASCII character 53)
key up control
end tell

Once the scripts are properly saved and their aliases placed in your Speakable Items folder, these additional steps need to be taken for them to work:

1) GUI Scripting must be turned on. Under System Preferences > Universal Access, check "Enable access for assistive devices."

2) Mouse Keys must be turned on. System Preferences > Universal Access > Mouse, select the Mouse Keys: On radio button.

3) In System Preferences > Speech > Speech Recognition > Settings, select the Speakable Items: On radio button. To activate a voice command entirely hands-free, select Listening Method: "Listen Continuously with keyword." You then have the option whether to actuallyusethe keyword; if you'd prefer not to use a keyword, select Keyword is: "Optional before commands." If necessary, click the Calibrate button to adjust the microphone input volume.

You should be all set at this point. If you choose not to use a spoken keyword or modifier key, then, thereafter, when your mouse cursor is hovering over a desired spot on the screen, simply speak the name of the saved script. application -- "Click," "Double-Click," "Triple-Click," or "Control-Click" (or "Right-Click") -- and the corresponding action should complete.

These scripts worked for me, using Mac OS 10.4.11. Your results may vary... Good luck.

TAG:

 

评分:0

我来说两句

jester.xu

jester.xu

软件测试从业者,认为自动测试有超大的发展空间,誓将自动进行到底!

日历

« 2024-05-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 4136
  • 日志数: 7
  • 建立时间: 2008-06-16
  • 更新时间: 2011-03-06

RSS订阅

Open Toolbar