Re: Swiftautomation...
Re: Swiftautomation...
- Subject: Re: Swiftautomation...
- From: Rick Gordon <email@hidden>
- Date: Tue, 22 Nov 2016 15:28:40 -0800
That all seems amazingly less arcane than all this ObjC stuff. Fits with
my expectations of programming syntax. Easy translation. I like it!
Rick Gordon
-------------------- On 11/22/16, 2:55 PM has said:
Three main differences between AppleScript and Swift:
1. Swift is really pedantic about code that throws errors. As in AS,
all app commands throw errors on failure, so you must type `try`
before them or they won't compile. e.g.:
try TextEdit().activate()
2. No implicit `get`. e.g.:
TextEdit().documents.first.name
only gives you the reference (name of first document of app
"TextEdit") when run.
To actually get the value you need to add a `.get()` call to the end:
TextEdit().documents.first.name.get()
3. Swift is a statically typed language (super pedantic). Sometimes it
can infer types from context, e.g.:
if try textedit.documents.first.exists() {
// do stuff with frontmost TextEdit document
}
other times you must tell it before it will let you do _anything_
useful with returned values. When in doubt, always add `as TYPE` after
a command, e.g.:
try finder.home.folders.name.get() as Array<String>
lets Swift (and SwiftAutomation) know that you want a list of strings
back. Or:
try itunes.currentTrack.get() as ITUItem
tells it you want a reference to the current track.
...
Like I say, code beta-ish but docs need good bit of work. If you can
avoid the disaster that is tutorial chapter, most of the rest if
fairly complete. Try the Examples chapter to get a flavor of AS vs
Swift syntax:
https://hhas.bitbucket.io/examples.html
The AppleScriptToSwift app is also your absolute best friend when
figuring out how to write a reference (specifier) or command using
Swift syntax. Appscript users LOVED this.
___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden