AppleScript 笔记

来源:互联网 发布:上传小说的软件 编辑:程序博客网 时间:2024/05/17 05:08

1. 清空回收站

tell application "Finder"
    empty the trash
end tell


2. "咚" 一声儿

been


3. 可以执行shell代码

例如: do shell script "ls"


4.定义变量

set n to "12" as number
set m to 12 as string
display dialog n
display dialog m


5.打开应用

tell application "System Events"
    tell process "Firefox"
        set frontmost to true
    end tell
end tell


6.每隔0.1秒 按键Hi 当按下 com 键停止

use framework "Foundation"
tell application "System Events"
    tell process "TextEdit"
        set frontmost to true
    end tell
    repeat
        keystroke "Hi"
        delay 0.1
        set flag to my BWAND((current application's NSEvent's modifierFlags()), (current application's NSCommandKeyMask)) > 0
        if flag is true then exit repeat
    end repeat
end tell

on BWAND(__int1, __int2)
    set theResult to 0
    repeat with bitOffset from 30 to 0 by -1
        if __int1 div (2 ^ bitOffset) = 1 and __int2 div (2 ^ bitOffset) = 1 then
            set theResult to theResult + 2 ^ bitOffset
        end if
        set __int1 to __int1 mod (2 ^ bitOffset)
        set __int2 to __int2 mod (2 ^ bitOffset)
    end repeat
    return theResult as integer
end BWAND


0 0