网上的几个applescript例子

清空idle进程
property ticsSinceActive : 0
property idleTime : 60 -- time to idle, in seconds
property timeLimit : 10 -- memory range, in minutes
property cpuUsage : {}

on idle
set maxTicCount to timeLimit * 60 / idleTime
tell application "System Events"
if exists (some process whose name contains "Illustrator") then
-- get reference to the app
set theIllustratorApp to some process whose name contains "Illustrator"
else
-- illustrator is not running
set ticsSinceActive to 0
set cpuUsage to {}
return
end if
set illustratorPID to unix id of theIllustratorApp
-- check if illustrator is inactive
if frontmost of theIllustratorApp is true then
set ticsSinceActive to 0
else
set ticsSinceActive to ticsSinceActive + 1
end if
-- take a running snapshot of cpu usage
set shellCmd to "ps -c -o %cpu='' -p " & illustratorPID
set end of cpuUsage to (do shell script shellCmd) as number
if (count of cpuUsage) is greater than maxTicCount then
-- trim off items more than 10 minutes old
set cpuUsage to items ((count of cpuUsage) - maxTicCount + 1) thru -1 of cpuUsage
end if
set maxCpu to 0
set aveCpu to 0
repeat with thisBit in cpuUsage
if thisBit > maxCpu then setmaxCpu to thisBit
set aveCpu to aveCpu + thisBit
end repeat
set aveCpu to aveCpu / (count of cpuUsage)
if ticsSinceActive > maxTicCount or maxCpu < 3 or aveCpu < 3 then
tell theIllustratorApp
activate
display alert "Shutting down Illustrator" message "Illustrator has been inactive for 10 minutes. Please verify that you are still using this application, or the system will shut it down." as critical buttons {"Close it", "Keep it running"} default button 1 giving up after 30
if button returned of the result is "Close it" or gave up of the result is true then
repeat 60 times
if exists document 1 then
close document 1 saving no
else
exit repeat
end if
end repeat
quit
else
set ticsSinceActive to 0
end if
end tell
end if
end tell
return idleTime
end idle


set backupFolder to (choose folder)
tell application "Finder" to set theseFolders to (get folders of backupFolder)
repeat with oneFolder in theseFolders
if (creation date of (info for oneFolder as alias) < (current date) - 30 * days) then
tell application "Finder" to delete oneFolder
end if
end repeat


检查程序是否运行
[code]global wasLoaded

on run
set wasLoaded to isAppLoaded("Safari")

idle
end run

on idle
set x to isAppLoaded("Safari")
if x and not wasLoaded then
display dialog "Safari was loaded."
set wasLoaded to true
else if wasLoaded and not x then
display dialog "Safari was quit."
set wasLoaded to false
end if
return 1 --will wait 1 second before checking again
end idle

on isAppLoaded(app_name)
tell application "System Events"
set app_list to every application process whose name contains app_name
if the (count of app_list) > 0 then
return true
else
return false
end if
end tell
end isAppLoaded
[/code]

自动把解压的文件放到Movie目录去
[code]on adding folder items to this_folder after receiving added_items

delay 0.2

set this_folder to alias "Liz's MBP:Users:liz:Downloads:Extract:"

set target_folder to alias "Liz's MBP:Users:liz:Movies:"

set fileList to {}

set fileList to my recursiveSearch(fileList, this_folder)

tell application "Finder"

repeat with aItem in fileList

if name extension of aItem is in {"avi", "wmv", "srt", "idx", "sub", "mkv"} then

if aItem exists then

move aItem to target_folder

end if

end if

end repeat

end tell

end adding folder items to


on recursiveSearch(theList, currentFolder)

tell application "Finder"

set theList to theList & (every file of currentFolder)

set folderList to (every folder of currentFolder)

repeat with newFolder in folderList

set theList to my recursiveSearch(theList, newFolder)

end repeat

return theList

end tell

end recursiveSearch[/code]

删除空文件夹
[code]--script to find empty folders and delete them

set pathoffolder to alias "Liz's MBP:Users:liz:Downloads:Extract:"

--change folder here

tell application "Finder"

repeat with oneFolder in (get folders of pathoffolder)

if (count items) of oneFolder is 0 or ((count items) of oneFolder is 1 and name of item 1 of oneFolder is ".DS_Store") then delete oneFolder

end repeat

end tell[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值