Jump to content
waldrumpus

[SOLVED] AppleScript that creates reminder freezes Alfred for a long time

Recommended Posts

I've created a workflow that adds a reminder to a pre-determined list in Reminders. E.g. if I type "buy Apples" into Alfred, it adds the item "Apples" to the list called "shopping list" in Reminders. The workflow uses an AppleScript to create the reminder.

 

The workflow looks like this: "Keyword > Run AppleScript > Post Notification"

 

This is the AppleScript:

on alfred_script(q)
	tell application "Reminders"
		tell list "Einkauf"
			set newremin to make new reminder
			set name of newremin to q
		end tell
	end tell
end alfred_script

If I run this script by itself in the Script Editor, it takes 2 to 3 seconds to execute. However, if I run the workflow, it takes about 40 seconds before the Notification at the end appears. During this time neither Alfred nor Reminders will respond.

 

Is there a way to speed up this process? Maybe there's a better way to execute scripts from within a workflow? It could be that the fault is entirely on Reminders' side; in which case I'd love to know if a workaround exists.

Share this post


Link to post
1 hour ago, waldrumpus said:

Keyword > Run AppleScript > Post Notification

 

Don't use Run NSAppleScript. Use a regular Run Script action with Language = /usr/bin/osascript (AS) instead.

 

Run NSAppleScript is executed on Alfred's main thread, which is why it's blocking.

Share this post


Link to post
2 hours ago, deanishe said:

Run NSAppleScript is executed on Alfred's main thread, which is why it's blocking.

 

That's the kind of thing I was hoping for. Excellent solution!

 

I configured it like this, with the "running instances: concurrently" being an important setting.

 

image.thumb.png.922ebb2a935240195ec7342dd29c2629.png

 

It still takes a large amount of time for the reminder to appear, but since Alfred remains responsive, I can continue to work immediately, and even fire off the next "buy ..." command, which is what's important to me.

Share this post


Link to post
On 5/12/2020 at 2:25 PM, waldrumpus said:

It still takes a large amount of time for the reminder to appear

 

It's very strange that it takes so long. Communicating with applications via AppleScript is certainly slow, but normally no more than two seconds, not 30+.

Share this post


Link to post
On 5/12/2020 at 11:56 AM, deanishe said:

Run NSAppleScript is executed on Alfred's main thread, which is why it's blocking.

 

I always wondered why would one run AppleScript on the main thread if `Run Script action with Language = /usr/bin/osascript (AS) instead` exists?

Share this post


Link to post
Posted (edited)
9 hours ago, deanishe said:

 

It's very strange that it takes so long. Communicating with applications via AppleScript is certainly slow, but normally no more than two seconds, not 30+.

 

I timed some consecutive executions; it takes 37 seconds on average until the Reminders app becomes responsive again and Alfred presents the notification at the end of the workflow. If I run the same script from the Script Editor, it takes about 3 seconds.

 

I assume the delay is located in the Reminders app, but I have no idea how to diagnose this further.

Edited by waldrumpus

Share this post


Link to post
6 hours ago, nikivi said:

 

I always wondered why would one run AppleScript on the main thread if `Run Script action with Language = /usr/bin/osascript (AS) instead` exists?

 

In my case it's because this is my first Alfred workflow and I'm just getting into things 😅

 

I was in fact working on writing a shell script that would execute the AppleScript when deanishe's reply arrived. The fact that the "Run Script" action has a setting for running osascript, and concurrently to boot, is of course fantastic.

Share this post


Link to post
8 hours ago, nikivi said:

I always wondered why would one run AppleScript on the main thread if `Run Script action with Language = /usr/bin/osascript (AS) instead` exists?

 

Because it looks like the right way to run an AppleScript if you don't already know it isn't. And sometimes, you want to run code within Alfred (e.g. calling display notification in Run NSAppleScript shows Alfred’s icon; calling it from a Run Script shows Script Editor’s icon).

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...