AppleScript Done!

Similar documents
Microsoft Word - 苹果脚本跟我学.doc

Windows XP

1.ai

Microsoft Word - template.doc

epub83-1

RunPC2_.doc

C/C++ - 字符输入输出和字符确认

Microsoft PowerPoint - ch6 [相容模式]

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

AL-MX200 Series

ebook140-9

Microsoft Word - 01.DOC

Chapter 9: Objects and Classes

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

WWW PHP

epub 61-2

untitled

IBM Rational ClearQuest Client for Eclipse 1/ IBM Rational ClearQuest Client for Ecl

mvc

Microsoft Word - 第3章.doc

RUN_PC連載_10_.doc

CANVIO_AEROCAST_CS_EN.indd

2017 CCAFL Chinese in Context

AL-M200 Series

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

IP505SM_manual_cn.doc

WinMDI 28

HLA-B27軟體

epub 94-3

Symantec™ Sygate Enterprise Protection 防护代理安装使用指南

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

Sophos Central 快速安裝手冊

2009 Japanese First Language Written examination

ebook140-8

2010 Japanese First Language Written examination

2009 Korean First Language Written examination

audiogram3 Owners Manual

科学计算的语言-FORTRAN95

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

Guide to Install SATA Hard Disks

Business Objects 5.1 Windows BusinessObjects 1

2015 Chinese FL Written examination

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

ebook65-5

C/C++ - 文件IO

Lorem ipsum dolor sit amet, consectetuer adipiscing elit

2 WF 1 T I P WF WF WF WF WF WF WF WF 2.1 WF WF WF WF WF WF

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

Microsoft Word - PHP7Ch01.docx

C/C++ - 字符串与字符串函数

國 立 政 治 大 學 教 育 學 系 2016 新 生 入 學 手 冊 目 錄 表 11 國 立 政 治 大 學 教 育 學 系 博 士 班 資 格 考 試 抵 免 申 請 表 論 文 題 目 申 報 暨 指 導 教 授 表 12 國 立 政 治 大 學 碩 博 士 班 論

C H A P T E R 7 Windows Vista Windows Vista Windows Vista FAT16 FAT32 NTFS NTFS New Technology File System NTFS

ebook70-19

2/80 2

INTRODUCTION TO COM.DOC

Collection of 2012 Examination Certificates

els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8

ebook70-11

穨control.PDF

概述

Bus Hound 5

ebook35-2


K301Q-D VRT中英文说明书141009

MATLAB介紹

医院信息系统门诊划价子系统

Computer Architecture

RUN_PC連載_12_.doc

软件测试(TA07)第一学期考试

GoFlex Home UG Book.book

Java 1 Java String Date

PTS7_Manual.PDF

1 SQL Server 2005 SQL Server Microsoft Windows Server 2003NTFS NTFS SQL Server 2000 Randy Dyess DBA SQL Server SQL Server DBA SQL Server SQL Se

穨文件1

2 SGML, XML Document Traditional WYSIWYG Document Content Presentation Content Presentation Structure Structure? XML/SGML 3 2 SGML SGML Standard Gener

入學考試網上報名指南

Microsoft Word - SupplyIT manual 3_cn_david.doc

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

附录J:Eclipse教程

級 任 介 紹 班 主 任 其 他 級 任 2A 羅 彩 岫 主 任 吳 毅 蕙 老 師 2B 徐 玲 老 師 陳 詠 詩 老 師 2C 梁 麗 興 老 師 尹 南 老 師 2D 曾 康 老 師 李 樂 雯 老 師 2E 黃 蕙 明 老 師

Microsoft Word - ChineseSATII .doc

PPBSalesDB.doc

DR2010.doc

untitled

Cadence SPB 15.2 VOICE Cadence SPB 15.2 PC Cadence 3 (1) CD1 1of 2 (2) CD2 2of 2 (3) CD3 Concept HDL 1of 1

untitled

CA-C750К

LOVE IS OVER LOVE LOVE LOVE LOVE IS EVERYTHING LOVE LOVE LOVE LOVER'S QUEEN LYDIA MAYBE TOMORROW MEN'S TALK MY DEAR MY FRIEND MY OH MY MY SUMMER DREAM

自动化接口

(2008) 主 张 教 师 在 课 文 教 学 中 应 让 学 生 有 意 识 地 注 意 语 块, 并 指 出 语 块 教 学 对 大 学 生 的 英 语 写 作 能 力 有 着 重 要 的 意 义 于 秀 莲 (2008) 以 大 学 生 为 受 试 对 象, 在 对 不 同 学 生 分 别

untitled

C/C++语言 - 分支结构

Microsoft PowerPoint - Lecture7II.ppt

CDWA Mapping. 22 Dublin Core Mapping

C/C++程序设计 - 字符串与格式化输入/输出

bbc_bond_is_back_worksheet.doc

Quick Start Guide

Transcription:

A!leSc"pt idoraemon Nathan

! Nathanapple 2

AppleScript! 6 AppleScript! 6 AppleScript! 6 AppleScript! 6 AppleScript! 6 Automator AppleScript! 8 AppleScript! 9! 9! 9 AppleScript! 10 AppleScript! 11 1100! 11 AppleScrip! 12! 12! 12! 12! 13! 14! 16! 17! 17 AppleScript! 18 AppleScript! 18 AppleScript! 18! 20! Nathanapple 3

! 20! 20! 21! 22! 23! 24 Tell! 24 If! 24! 25 Considering/Ignoring! 26! 28! 28! 29! 29! 29! 30! 31 Try! 31 Try! 31 AppleScriptError! 31 Timeout! 32! 33 Alias! 33 POSIX! 33! 34! 34! Nathanapple 4

! 35! 35! 35! 36 run open! 36! 37! 37! 39 me! 39 script! 39 script! 39 script! 40 AppleScript! 41! 41 AppleScript! 41 Mac OS! 42! 43! Nathanapple 5

AppleScript apple apple apple apple AppleScript (Open Scripting Architecture) AppleScript (AppleScript Component) Apple (Apple Event Manager) apple apple apple apple apple apple apple apple apple apple apple apple apple! Nathanapple 6

AppleScript AppleScript apple apple apple 1 AppleScriptXcodeAppleScript Xcode GUI AppleScript Studio! Nathanapple 7

! Nathanapple 8

AppleScript 2 tell application Snow Leopard 3 2 Mac OS 10.5 10.4 AppleScript 3 AppleScript 2.3 (118)Mac OS X 10.6 2.3! Nathanapple 9

apple apple apple AppleScript apple apple apple apple apple apple apple 4 MacAdobe Microsoft! Nathanapple 10

tell application "Finder" make new folder at desktop with properties {name:"test"} repeat with a from 1 to 100 make new folder at folder "Test" of desktop with properties {name:a as string} end repeat end tell tell application "Finder" activate make new folder at folder "Desktop" of folder "Nathan" of folder "Users" of startup disk with properties {name:" "} set name of folder " " of folder "Desktop" of folder "Nathan" of folder "Users" of startup disk to "Test" make new folder at folder "Test" of folder "Desktop" of folder "Nathan" of folder "Users" of startup disk with properties {name:" "} set name of folder " " of folder "Test" of folder "Desktop" of folder "Nathan" of folder "Users" of startup disk to "1" make new folder at folder "Test" of folder "Desktop" of folder "Nathan" of folder "Users" of startup disk with properties {name:" "} set name of folder " " of folder "Test" of folder "Desktop" of folder "Nathan" of folder "Users" of startup disk to "2"!...! -- 196!... end tell 5 tell application 10.5 10.4! Nathanapple 11

AppleScrip Identifier Keyword! Boolean Number IntegerReal 6 AppleScript Language Guide developer.apple.com! Nathanapple 12

Text String Date Constant List Record firstname of {firstname:"idoraemon", lastname:"nathan"} -Class of class of "string" as -- "1.99" as real -- Real1.99Text "1.99" as integer -- Integer2 "1" as real -- Real1.0 --List "text" as list -- {"text"} 7 String Unicode TextAppleScript 2.0Text Apple AppleScript Language Guide 2008 3 text, string, and Unicode text will all compare as equal! Nathanapple 13

1.99 as list -- {1.99} {a:1, b:2} as list -- {1, 2} -- "text2" as number --Text 1 as record -- {1, 2} as record -- 8 Option option / option > 9 Java C3/2=1 AppleScript (3 as integer) / (2 as integer)1.5! Nathanapple 14

& apple apple apple! Nathanapple 15

"Text" & 1 --"Text1" (Text ) 1 & "Text" --{1, "Text"} List {name:"a"} & "b" --{name:"a", «class ktxt»:"b"} (Record) 3 & {name:"a"} --{3, "a"} (List) {1, 2, 3} & {4, 5, 6} --{1,2,3,4,5,6} List - {1, 2, 3} & 4 & 5 & 6 -- {a:1, b:2} & {c:3} --{a:1, b:2, c:3} Record - -- "Text" & {name:"a"} -- Record {name:"a"} & 3 -- IntegerRecord every character of "" characters of "A String" --{" ", " ", " ", " ", " "} --{"A", " ", "S", "t", "r", "i", "n", "g"} words of "A string" --{"A", "string"} every word of " " --{" ", " ", " ", " ", " "} characters 3 through 5 of "A String" --{"S", "t", "r"} -List words 3 through 5 of " " --{" ", " ", " "} -List word 2 of "This is a text" --"is" -Text character 3 of "This is a text" --"i" -Text ninth character of "This is a text" --"a"applescript apple apple apple apple Finder tell application "Finder" every file of desktop files of desktop --List -- every folder of desktop folders of desktop -- List -- 10! Nathanapple 16

name of every file of desktop --List end tell tell application "Finder" every file of desktop whose name begins with "a" -- a every file of desktop where its name contains "a" --a end tell End-of -line comment Block comment apple apple apple apple 11 # 2.0 AppleScript Unix! Nathanapple 17

AppleScript apple apple! Nathanapple 18

make v : Make a new element make new type : the class of the new element at location specifier : the location at which to insert the element [to specifier] : when creating an alias file, the original item to create an alias to or when creating a file viewer window, the target of the window [with properties record] : the initial values for the properties of the element specifier : to the new object(s) tell application "Finder" make new folder at desktop -- -- makenew atfolder type desktop location specifier -- make new folder at desktop with properties {name:"applescript"} --Record -- AppleScript end tell! Nathanapple 19

set name to value as type --as type set myresult to the result of (make new folder at desktop) -- tell app finder apple apple apple apple apple set message to "" -- message run anewscript displaya("") ------------------------------ ---- script anewscript -- -- displaya -- 12! Nathanapple 20

set message to "" -- message display dialog message --message end script ---- ---- on displaya(message) --displaya --message display dialog message --message end displaya ---- Record List set a to 1 set b to a display dialog " a=" & a & "; b=" & b --a 1 --ba -- a b set b to 0 --b0 display dialog "ba=" & a & "; b=" & b --a b Record List set a to {1, 2, 3, 4, 5} set b to a -- a List --balist! Nathanapple 21

display dialog " a=" & a & "; b=" & b -- a b set item 1 of b to 0 -- List b 0 display dialog "ba=" & a & "; b=" & b --a b copy set a to {1, 2, 3, 4, 5} set b to 1 copy a to b display dialog " a=" & a & "; b=" & b -- a List --copy --balist -- a b set item 1 of b to 0 display dialog "ba=" & a & "; b=" & b -- List b 0 --a b property Label : value property counttimes : 0 set counttimes to counttimes + 1 display dialog "" & counttimes & " " 13! Nathanapple 22

apple apple apple apple apple! Nathanapple 23

appletell referencetoobject to statement apple tell referencetoobjectend tell tell front window of application "Finder" to close -- tell application "Finder" close front window end tell -- appleif boolean then statement apple if boolean1 then statement1 else if boolean2 then statement2 else statement3 end if set mark to 99 --! Nathanapple 24

if mark 60 and mark < 80 then set response to "You passed the exam" else if mark 80 then set response to "Congratulations! You're smart" else set response to "Sorry. You failed" end if display dialog response repeat --do something end repeat repeat n times --do something end repeat repeat until boolean --do something end repeat repeat while boolean --do something end repeat repeat with loopvariable from startvalue to stopvalue by stepvalue --do something end repeat! Nathanapple 25

*List repeat with loopvariable in list --do something end repeat set mylist to {"Hello", "Hi", "Hey", "Goodbye"} --List -- repeat with i in mylist display dialog (contents of i) -- List set (contents of i) to "oh" -- List"oh" end repeat considering attribute1 but ignoring attribute2 --compare texts end considering 14 1.10.1 > 1.9.4 false(considering numeric strings)true! Nathanapple 26

! Nathanapple 27

Display Dialog display dialog "" display dialog " " buttons {" ", " "} default button " " with title " " with icon note giving up after 5 apple apple apple apple apple display dialog "" default answer "" 15 AppleScript Studio Xcode! Nathanapple 28

apple apple apple display alert " " message "" as warning choose from list {"", "", ""} with title "" with prompt " " default items {""} with empty selection allowed and multiple selections allowed apple apple apple apple apple apple Choose File Name choose file name with prompt " " default name "" default location file "Macintosh HD:Users"! Nathanapple 29

Choose Folder choose folder with prompt " " default location file "Macintosh HD:Users" with invisibles, multiple selections allowed and showing package contents Choose File choose file of type {"txt"}! Nathanapple 30

try --statement end try tell application "Finder" make new folder at desktop with properties {name:"applescript"} end tell display dialog "Success " try --do something at risk on error errtext number errnum -- do something to handle error end try error " " number 999 16 try! Nathanapple 31

try display dialog " AppleScript Folder " tell application "Finder" make new folder at desktop with properties {name:"applescript Folder"} end tell on error etext number enum if (enum = -48) then display dialog "\n" & etext else if (enum = -128) then display dialog "\n" & etext end if end try with timeout of x seconds --x --wait for something end timeout with timeout of 3 seconds display dialog " " end timeout display dialog " " 17 error error! Nathanapple 32

set myalias1 to alias "Macintosh HD:System:Library:CoreServices:Finder.app:" set myalias2 to alias "Macintosh HD:Users:Nathan:Desktop:example.txt" path to path to documents folder -- alias path to library folder from system domain -- alias POSIXPOSIX file POSIX path of alias "Macintosh HD:System:Library:CoreServices:Finder.app:" -- "/System/Library/CoreServices/Finder.app/" POSIX file "/Users/Nathan/Desktop/example.txt" -- file "Macintosh HD:Users:Nathan:Desktop:example.txt" 18 AliasMac OS windows 19 MacPOSIX /AppleScript! Nathanapple 33

set myfile to alias "Macintosh HD:Users:Nathan:Desktop:example.txt" read myfile set afile to alias "Macintosh HD:Users:Nathan:Desktop:example.txt" set fp to open for access afile with write permission -- write "abc" to fp -- close access fp -- 20 21! Nathanapple 34

on HelloWorld() display dialog "Hello, world" end HelloWorld -- -- -- HelloWorld() -- on Hello(somebody, howlong) display dialog somebody giving up after howlong end Hello -- -- -- Hello("Apple", 2) -- Hello("Microsoft", 1) Hello("User", 3) on Hello to somebody for howlong display dialog somebody giving up after howlong end Hello -- -- Hello to "Apple" for 2 --! Nathanapple 35

Hello for 1 to "Microsoft" -- Hello to "User" for 3 on add(x, y) set answer to (x + y) return answer end add display dialog add(1, 2) -- add run open on open names set pathnamesstring to "" -- repeat with i in names -- -- set ipath to (i as text) 22 AppleScript Language Guide! Nathanapple 36

set pathnamesstring to pathnamesstring & ipath & return end repeat -- tell application "TextEdit" set paragraph 1 of front document to pathnamesstring end tell return end open idle quit on idle beep 2 display dialog " " giving up after 1 return 5 end idle -- --5 on quit display dialog " " buttons {" ", " "} -- if button returned of result = " " then continue quit -- end if end quit! Nathanapple 37

on adding folder items to thefolder after receiving theitemlist -- display dialog ((count theitemlist) & " ) as text buttons {" ", ""} -- if button returned of result = "" then tell application "Finder" open thefolder end tell end if end adding folder items to! Nathanapple 38

property dialogtext : "ShowMe " script ShowMe display dialog dialogtext on showsomething() -- display dialog "" end showsomething end script run ShowMe showsomething() of ShowMe tell ShowMe run -- showsomething() -- end tell set thepath to ((path to desktop) as text) & "Script to Load.scpt"! Nathanapple 39

-- set thescript to load script file thepath -- run ShowMe of thescript -- showsomething() of ShowMe of thescript -- set thepath to ((path to desktop) as text) & "Script to Load.scpt" set thescript to load script file thepath run ShowMe of thescript -- set dialogtext of thescript to "" run ShowMe of thescript -- store script thescript in file thepath with replacing! Nathanapple 40

AppleScript about above after against and apart from around as aside from at back before beginning behind below beneath beside between but by considering contain contains contains continue copy div does eighth else end equal equals error every exit false fifth first for fourth from front get given global if ignoring in instead of into is it its last local me middle mod my ninth not of on onto or out of over prop property put ref reference repeat return returning script second set seventh since sixth some tell tenth that the then third through thru timeout times to transaction true try until where while whose with without! Nathanapple 41

! Nathanapple 42

! Nathanapple 43