johnathanz Posted May 11, 2020 Posted May 11, 2020 I'm modifying the Alfred Notion Workflow: https://github.com/wrjlewis/notion-search-alfred-workflow Here's my modified version: https://www.dropbox.com/s/5gk76u8aln22opc/Notion Search_JZ.alfredworkflow?dl=0 Basically trying to pass whatever user's chosen from "Script Filter" to "Run script" Unfortunately, it's not working with AppleScript - fails because Alfred adds trailing white space (stripping it out doesn't work 🤔) set theQuery to item 1 of argv tell application "System Events" to tell process "Notion" click menu item "New Window" of menu 1 of menu bar item "File" of menu bar 1 end tell return theQuery end run tried a Python Run Script (which opens 2 New Windows 🤯) import sys from subprocess import Popen, PIPE query = sys.argv[1] script = ''' # activate application "Notion" tell application "System Events" to tell process "Notion" click menu item "New Window" of menu 1 of menu bar item "File" of menu bar 1 end tell''' p = Popen('osascript', stdin=PIPE, stdout=PIPE, stderr=PIPE) p.communicate(script) sys.stdout.write(query) Any idea: 1) Why the AppleScript adds trailing spaces? AND 2) Why the Python Run Filter passing parameter using `sys.stdout.write()` to a Python Run Script to Open URL opens the URL twice? Thanks!
deanishe Posted May 11, 2020 Posted May 11, 2020 (edited) 1 hour ago, johnathanz said: with AppleScript - fails because Alfred adds trailing white space Alfred doesn’t add it, osascript does. It’s just another AppleScript weirdness. 1 hour ago, johnathanz said: Why the Python Run Filter passing parameter using `sys.stdout.write()` to a Python Run Script to Open URL opens the URL twice? What do you mean "it opens the URL twice"? I've never seen an Open URL do that, and your log says it's only being called once. What behaviour makes you say the URL is being opened twice? Notion opening two windows? In that case, it's probably a timing screw-up in your code. Simulating a menu click isn't synchronous. That code will return before Notion actually responds to the click. It's likely that your Open URL command is reaching Notion before it has acted on the "New Window" menu click, so it's opening one window in response to your "Open URL" action and then creating another showing the last active note (the one you just told it to open via the Open URL action) as a result of the "New Window" command. Try removing the "New Window" bit. Edited May 11, 2020 by deanishe
vitor Posted May 11, 2020 Posted May 11, 2020 To remove the trailing whitespace, add a Transform Utility.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now