清空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
检查程序是否运行
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
自动把解压的文件放到Movie目录去
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
删除空文件夹
--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
分享到:
相关推荐
Applescript 初学者教程,让更多的人了解Applescript,用好Applescript
因为网上关于applescript的资源实在是太少了,刚好最近在学习,分享给大家,如果有什么问题,可以随时私信联系我。 以下是功能说明: 1.框架是易语言写的中控框架,tcp连接控制mac虚拟机; 2.主要功能包括自动登录...
包含书籍: 1. AppleScript跟我学_苹果脚本语言入门的好资料.pdf 2. basics-of-applescript.pdf 3. AppleScript权威指南.pdf 相关链接: https://github.com/unforswearing/applescript
非常好的入门教程,本人看着这个教材掌握了ASOC开发
Nathan编著(43页) - AppleScript简明基础教程[AppleScript Done!.pdf] 第一章 AppleScript入门! 第二章 快速上手AppleScript编辑器! 第三章 AppleScrip语言初步! 第四章 读懂AppleScript字典! 第五章 变量和属性! ...
AS 是能够帮你在 mac 上实现自动化的有效工具,他通过类英语的语法,以及简单的编程功能,帮助你摆脱机械化的劳动。...AppleScript 包括如下三部分: AppleScript 语言 AppleScript 脚本文件 AppleScript 脚本解释器
AppleScript学习笔记(二)AppleScript的四种数据类型对应的Example,一些脚本代码。
AppleScript 简单教程 输出 hello world, 发邮件的 AppleScript
Mac OS X AppleScript Language Guide
Apple Script Language guide
AppleScript document is for those who wanna learn Apple script for automation in testing or integrated tasks. very useful!
包含书籍: 1. AppleScript跟我学_苹果脚本语言入门的好资料.pdf 2. basics-of-applescript.pdf 3. AppleScript权威指南.pdf 相关链接: https://github.com/unforswearing/applescript
AppleScript初学者.pdf 本书主要介绍applescript 的编程说明,内容比较详尽,建议请先看过applescript脚本跟我学后,再看这本书!
AppleScript初学者关于AppleScript:AppleScript很简单──保证比VB还简单,但很实用!学起来很轻松!学会之后你会发现你节约了很多时间,摆脱了很多机械性的无聊琐事。 关于创作目的:国内目前有关AppleScript的...
AppleScript Reference Guide
AppleScript简明基础教程 简单明了,适合新手学习
学个玩 AppleScript跟我学 了解一下 不吃亏啊 2积分 买不了吃亏 买不了上当 相信哥 走一个
通俗易懂的AppleScript讲解,入门必备,实例多且清晰!