Does anyone have a simple example for a scriptable App in Swift in Xcode for macOS? I mean one that exposes objects and functions to applescript?
I've checked all examples that I could find. But for me they get me confused about whether they are accessing the actual and already existing instance of a class or whether they are creating an instance with AppleScript, or just using the class definition to call some function. Also the way they are defined in the .sdef file does not help. It would be great if someone had a really simple example, stripped down to bare minimum that 1) defines a class with a single function, 2) creates an instance of the class inside appDelegate and then 3) the function of the specific instance is called using appleScript. 4) It would be great if the function could do something in the GUI, such as change a text of a Label.
AppleScript
RSS for tagAppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.
Posts under AppleScript tag
43 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
My grand plan is to have a rule in Apple Mail that automatically adds a custom header to each message. This rule would be last and each of the rules before that last rule would check for the presence of this custom header and therefore no longer work for incoming mail.
So the plan is to have a small AppleScript that adds this header but I am running into a block which hopefully someone can help we with. I have the following pieces of code:
tell application "Mail"
activate
set myHeader to make new header with properties {name:"X-MySecretHeader", content:"It's been set"}
end
The last statement fails with the following error:
Mail got an error: Can’t make or move that element into that container.
I then changed the code slightly:
tell application "Mail"
activate
set theMessage to get item 1 of (get selection)
set theHeaders to headers of theMessage
set myHeader to duplicate item -1 of theHeaders
end
Mail got an error: Headers can not be copied.
That last error seems to indicate that I'm trying to do something which cannot be done. I have also tried to do this in a tell block to theMessage but that did not change anything.
Anyone has an idea?
How to create a UTF-8 encoded text file using do shell script?
As I understand it, the command should start with do shell script. And what to write next?