As an app developer, itās near impossible to think of all the ways people will want to use your app. Wouldnāt it be cool to let your users create scripts to customize your app to their own personal needs? With Applescript and Javascript for Automation (JXA), you can! In this making a Mac app scriptable [ā¦]
Hi Sarah,
The link for the starter version of the project is actually pointing to the final version of the project. Anyway, very interesting tutorial.
Thanks
John
Compiler error: Type 'Any" has no subscript membersā¦
I had to modify two functions to get the code to compile under XCode 8 and Swift 3.
Iām new to Swift, so there are probably many ways to improve my code, but it does compile and work now.
func receivedTasksChangeNotification(_ notification: Notification) {
if let notificationObject = notification.object as? [String:Any] {
if let newData = notificationObject["newTasksData"] as? [Task] {
completeTaskData = newData
refreshDisplay()
}
}
}
func receivedSingleTaskChangeNotification(_ notification: Notification) {
if let notificationObject = notification.object as? [String:Any] {
if let newData = notificationObject["newTaskData"] as? Task {
let newID = newData.id
// update an existing task with the new data and return
for (index, task) in completeTaskData.enumerated() {
if task.id == newID {
completeTaskData[index] = newData
refreshDisplay()
return
}
}
// otherwise, create a new Task with the specified data
completeTaskData.append(newData)
refreshDisplay()
}
}
}
If your AppleScript class is called āmail messagesā then it is probably backed by an AppDelegate property called something like āmailMessagesā - that is what you need to capitalise and put into the function call in place of āTasksā.
nice tutorial, but I am struggling with custom commands. When I execute your custom command script with the final project I get an error.
error "Scriptable Tasks got an error: task id \"67D3FA85-C8B9-4987-8E13-9B615A067338\" doesnāt understand the āĀ«event TaSktextĀ»ā message." number -1708 from task id "67D3FA85-C8B9-4987-8E13-9B615A067338"
What is the correct syntax to call a method from Apple Script?
When you open the Dictionary for the app in the Script Editorās Library, can you see the mark command? If not, close the Dictionary window, delete it from the Library and re-import it from the app.
Do you have more than one copy of the app running? This can happen as the Script Editor tries to keep hold of a running copy, even while you are editing and compiling a new copy. If so, close them both and do a fresh build & run from Xcode - this is only a problem dug in development.
The syntax for calling the custom command is shown in two sample script files: ā7. Custom Command.scptā in either the Apple Script or theJavaScript folder.
Hopefully these pointers will solve the issue, but please reply to this thread if you are still having problems.
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]