Re: Swiftautomation...
Re: Swiftautomation...
- Subject: Re: Swiftautomation...
- From: Jean-Christophe Helary <email@hidden>
- Date: Wed, 23 Nov 2016 09:11:05 +0900
> On 2016 Nov 23, at 8:28, Rick Gordon <email@hidden> wrote:
>
> That all seems amazingly less arcane than all this ObjC stuff. Fits with my expectations of programming syntax. Easy translation. I like it!
Have you filled your radars ? ;)
Just in case you don't know what to do:
1) go to https://bugreport.apple.com
2) create a bug report "enhancement" to "macOS" to add a standard library to Applescript
3) since such reports are closed, make sure that you duplicate the report on http://openradar.appspot.com
4) back to https://bugreport.apple.com
5) create a bug report "enhancement" to "macOS" to add "Swiftautomation" to macOS 10.13
6) same as 3) above.
My own reports are:
http://openradar.appspot.com/29329704
http://openradar.appspot.com/29363517
JC
>
> 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
_______________________________________________
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