白城师范学院贴吧,江泽名,百世元婴,薅羊毛,糖果空投

Automate Daily Chores With Applescript-www.11aabb.com

Posted on June 17, 2018 by hanson

Automate Daily Chores With AppleScript I had a moment of self-doubt the other morning: am I man or automaton? The question came up when I fired up my office .puter and started manually launching one set of programs and changing the statuses on others. "Why," I asked myself, "do I do the same set of repetitive tasks every morning and every evening when I have AppleScript?" I couldn’t answer my own question. So I fired up AppleScript Editor (Applications/Utilities), and started to type. My goal was to create a script that would perform all the little steps I take at the beginning and end of each .puting day. This is what I came up with: set s to display dialog "Arriving or Leaving?" buttons ["Arriving", "Leaving"] default button "Arriving" if button returned of s is equal to "Arriving" then tell application "Mailsmith" set auto checking enabled to true check mail end tell tell application "iChat" activate log in set status message to "Working" end tell tell application "Echofon" activate end tell tell application "NetNewsWire" activate end tell else tell application "iChat" quit end tell tell application "Mailsmith" set auto checking enabled to false end tell tell application "Echofon" quit end tell tell application "NetNewsWire" quit end tell tell application "Finder" activate set frontmost to true set visible of every process whose visible is true and name is not "Finder" to false end tell end if The first line of script creates a dialog box that asks me if I’m arriving or departing, setting the default answer to arriving. You could add additional options by inserting them in quotation marks, separated by .mas, in the list after buttons. For instance, ["Arriving", "Lunch", "After Lunch", "Departing"] The next line checks my response. If I click on Arriving, the script carries out the first series of application actions. If I click on Departing, it performs the second batch (after else). For those of you who haven’t used AppleScript before: You’ll see the format for each individual action is the same: tell specifies a program, the indented block tells it what to do, and the end tell ends that section. Some of the .mands in those indented blocks are generic (activate). Others are more specific to the particular program. The latter are found in the AppleScript Editor’s libraries (Window -> Library); if you don’t see the program you want, click the + (plus sign) in the top of the Library window and select the program from your Applications folder. For instance, for my e-mail client Mailsmith, I added one .mand that changes the property of auto checking (set auto checking enabled to true) and another to add the check mail. Similarly with iChat: log in is a simple .mand, while set status message to "Working" is only slightly more .plicated. You can script any application to activate itself first thing in the morning. True, you could add them to a list of Login Items for your user account in System Preferences’ Accounts pane. But I like the finer control over when and how they launch that I get from AppleScript. To make this script easy to run, I save it as an application in AppleScript Editor (File -> Save As, then selecting Application as the file format). This creates a self-contained application that I can run at will. If I really wanted to be regimented about it, I could add an iCal event that would launch the app every morning at 9:00 a.m. and every evening at 5:00. But I don’t work that way. This script might save me just a tiny sliver of time each day. But I suspect that, over several years, it adds up to tens of hours when I don’t have to be a robot. 相关的主题文章: