objc-appscript

PreviousUpNext appscript / aem

12. Command Examples

get

Get the name of every folder in the user's home folder:

// tell application "Finder" to get name of every folder of home
[[[finder get: [[[FNApp home] folders] name]] send]

Note that if the direct parameter is omitted from the argument list, the reference that the command is invoked on is used instead. For example, the above example would normally be written as:

[[[[[finder home] folders] name] get] send]

set

Set the content of a TextEdit document:

// tell application "TextEdit" to set text of document 1 to "Hello World"
[[[[[[textedit documents] at: 1] text] set] to: @"Hello World"] send]

count

Count the words in a TextEdit document:

// tell application "TextEdit" to count words of document 1
[[[[[textedit documents] at: 1] words] count] send]

Count the items in the current user's home folder:

//tell application "Finder" to count items of home
[[[[finder home] count] each: [FNConstant item]] send]

(Note that the each parameter is required in Finder's count command.)

make

Create a new TextEdit document:

// tell application "TextEdit" to make new document ¬
// with properties {text:"Hello World\n"}
[[[[textedit make]
 new_: [TEConstant document]]
 withProperties: [NSDictionary dictionaryWithObjectsAndKeys:
 @"Hello World\n", [TEConstant text], nil]]
 send]

Append text to a TextEdit document:

// tell application "TextEdit" to make new paragraph ¬
// at end of text of document 1 ¬
// with properties {text:"Yesterday\nToday\nTomorrow\n"}
[[[[[textedit make]
 new_: [TEConstant paragraph]]
 at: [[[[TEApp documents] at: 1] text] end]]
 withData: @"Yesterday\nToday\nTomorrow\n"]
 send]

duplicate

Duplicate a folder to a disk, replacing an existing item if one exists:

// tell application "Finder" to ¬
// duplicate folder "Projects" of home to disk "Work" with replacing
[[[[[finder home]
 folders] byName: @"Projects"] 
 duplicate]
 to: [[FNApp disks] byName: @"Backup"]]
 replacing: ASTrue]
 send]

add

Add every person with a known birthday to a group named "Birthdays":

// tell application "Address Book" to add ¬
// every person whose birth date is not missing value ¬
// to group "Birthdays"
[[[[[addressBook people]
 byTest: [[ABIts birthDate] notEquals: [ABConstant missingValue]]]
 add] to: [[ABApp groups] byName: @"Birthdays"]]
 send]
PreviousUpNext

AltStyle によって変換されたページ (->オリジナル) /