Jump to content

dfay

Member
  • Posts

    1,054
  • Joined

  • Last visited

  • Days Won

    61

Posts posted by dfay

  1. Ok I've got it working.  Here's the code for the script filter, which also requires that you check "Alfred filters results" and replace the access token in the code:

     

    #!/usr/bin/python
    
    import json
    import os
    import urllib
    
    def my_generator(json_input):
    	if isinstance(json_input, dict):
    		for k, v in json_input.iteritems():
    			if k == 'title':
    				ti = v.replace('"', '').replace(',', '').replace(':','')
    			elif k == 'identifier':
    				arg = v
    			elif k == 'type':
    				subti = v
    			else:
    				for child_val in my_generator(v):
    					yield child_val
    		yield json.dumps({u'title': ti, u'arg': '['+ti+'](ulysses://x-callback-url/open?id='+arg+')', u'subtitle': subti})
    	elif isinstance(json_input, list):
    		for item in json_input:
    			for item_val in my_generator(item):
    				yield item_val
    
    tmp = os.popen('/Applications/xcall.app/Contents/MacOS/xcall -url "ulysses://x-callback-url/get-root-items?recursive=YES&access-token=youraccesstokengoesHERE"').read()
    
    ulyssesLib = json.loads(urllib.unquote(tmp).decode('utf8'))
    
    items = json.loads(urllib.unquote(ulyssesLib['items']))[0]
    
    print('{"items":'+str(list(my_generator(items))).replace('\\\'','').replace('\'','')+'}')

    It searches the sheet/group titles for the query.

    it outputs a Markdown formatted URL, so to paste it into Ulysses you need to use Edit > Paste from > Markdown a.k.a. command-option-V

     

  2. Well I got a version of ul working last night, but it requires manually loading all the sheet titles and URLs into a list filter.  From a CSV that's generated by a workflow in Workflow for iOS.  Working as a proof of concept :wacko: .  Since there seems to be no way to get a sheet identifier from the sheet file itself, it seems we would need to use Ulysses get-root-items callback URL, and parse the whole library.

     

    I began to pick apart & try to replicate what the Workflow workflow does (it came from here: https://workflow.is/workflows/84934276b51643678643e1aa326637bd , & I modified it to output title, identifier, [title](ulysses url w/identifier) to a CSV), and convert it to write JSON which can then be read by a Script Filter.

     

    The xcall utility linked above was really helpful at that stage.

     

    Where I ran into trouble (and went to sleep) was at the stage of parsing the JSON.  

     

    Here's the code I was running (in CodeRunner -- had to manually authenticate with Ulysses first, too):

     

    #!/usr/bin/python
    
    import json
    import os
    
    tmp = os.popen('/Applications/xcall.app/Contents/MacOS/xcall -url "ulysses://x-callback-url/get-root-items?recursive=YES&access-token=your token here"').read()
    
    ulyssesLib = json.loads(tmp)['items']
    print (ulyssesLib)

    When I look at that output, it looks to me like it's a (long, messy) list of dictionaries but running type(ulyssesLib) says it's unicode.

     

     

  3. 56 minutes ago, robwalton said:

    This would be a very cool feature. I guess we'd just want to paste it at the cursor location of the currently open sheet? I loose track of keyboard modifiers: would this warrant a new ul (for link) command?

    My initial thought would be Option key and copy the link to the clipboard .  But using ul instead you could then have copying to clipboard as default behavior and paste at cursor location as a modifier (or vice versa).  

  4. 47 minutes ago, robwalton said:

    Sond like there are two issues:

    1. The workflow should only look in 'On My Mac' if preference is set.

    2. I don't see the 'On My Mac' prefixes that you see. Is it possible you once enabled 'On My Mac' and had some stuff in there? The workflow will find old things on disk---this would not account for everything having 'On My Mac' in front, but could cause confusion

     

    Will look at #1. Regarding #2, could you check that you don't have stuff in 'On My Mac' that be causing confusion

     

    P.S. Could just disable On My Mac support until I have time look at it properly. This was just a stepping stone to supporting external folders.

     

     

    Let me see.  I have On My Mac turned off in Ulysses > Preferences > Library .  I just tried turning it on & it's definitely empty (there's just the empty Inbox).  Interestingly I added a sheet to it, and the workflow doesn't find it....but it's still showing everything else as being in 'On My Mac'

     

    And if I use the ug command, and search for 'On My Mac' it shows my groups as expected whereas if I search for "iCloud" (where they are) I get no results.

     

    Odd, isn't it?  It's not really a problem since the workflow works perfectly otherwise.  

     

    I poked around in the XML in the library a bit and it seems that the DisplayName for my root is set to "On My Mac" even though it is in fact in iCloud.  Seems like a Ulysses bug that is otherwise invisible but which the workflow may make evident by using the DisplayName?  Just a guess.

  5. Is there any chance you could add a keyboard modifier to uf to copy the link to a sheet instead of opening the sheet?  Ulysses lacks an easy way to create links between sheets (the one thing I miss from abandoning NVAlt....) and this would be a great way to fill that gap. 

  6. Wow this is looking great.  I was writing some AppleScript to clean up a bunch of Ulysses sheets (by adding BibDesk keywords as native Ulysses keywords rather than hashtags, now that Ulysses keywords are exposed through the new URL scheme update) and found myself thinking someone should write a nice tidy API for the URL scheme....

     

    One quirk I've noticed with the Ulysses Alfred workflow -- even though i have "On My Mac" turned off in Ulysses prefs., and all my sheets are in iCloud, the subtitle for the workflow always shows the path as /On My Mac/correct path from here on out .  Everything else works, it just says my stuff is On My Mac instead of in iCloud.

     

     

     

     

  7. I got ExactScan b/c there was no native Mac driver for my scanner, & ExactScan supports it.  It also lets you scan via AppleScript, with lots of customization options.  Not cheap but may be worth it depending on your needs (it was cheaper than buying a new scanner, which sealed the deal for me).

     

     

  8. 2 hours ago, deanishe said:

    What? Like grep for?

     

    update_settings and run_in_background are your huckleberries:

    
    grep -R update_settings . | grep -v /workflow/
    grep -R run_in_background . | grep -v /workflow/

    That should filter out the library itself. Hopefully, @vitor will show up with some of his CLI wizardry to expand that to return the folders the library wants installing in :) 

     

    Thanks 

     

    That found update_settings in 

    But none of mine (b/c I'm too lazy to set up updating ;) )

     

    But we should also be checking the library version for any of our own (and presumably any which the devs don't update too), correct?

  9. Hmm.  I did the 10.12.4 upgrade last night and now it needs to click pop up button 5 instead of 4 ... don't notice what changed in the UI but something must have.  You may need to do some trial and error to get the correct pop up button # -- I use Mail Add-On and MailTags which modify the Mail window, so the # of the button may be different in your case.  Such are the perils of being forced to use UI scripting.

     

    It may be an issue with the way Alfred calls scripts, and the handling of subprocesses / System Events therein.  It's working for me with a Run Script > osascript (AS) > input as {query} object in the workflow.

     

    But...I just checked and it works as Run NSApplescript as well.

     

    Here's the exact code I am using with Run NSApplescript:

     

    on alfred_script(q)
      set theQuery to q
    
    set myComment to "xxxx@boards.trello.com"
    set theName to "Some name"
    set theAddress to "Some email address"
    set mySignature to "blank"
    
    
    try
    	set the clipboard to myComment
    	tell application "Mail"
    		set theSelection to selection
    		set theForwardedMessage to forward (item 1 of theSelection) with opening window
    		tell theForwardedMessage
    			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
    		end tell
    		activate
    		tell application "System Events" to keystroke "v" using {command down}
    		delay 1
    		
    		try
    			set message signature of theForwardedMessage to signature mySignature
    			
    		on error --BUG SIERRA 
    			
    			tell application "Mail" to activate
    			tell application "System Events"
    				tell process "Mail"
    					click pop up button 5 of window 1
    					delay 0.1
    					keystroke "b" --put here the first letter of the name of your signature 
    					delay 0.1
    					keystroke return
    					delay 0.1
    				end tell
    			end tell
    			
    			
    		end try
    		
    		-- send theForwardedMessage
    	end tell
    end try
      return theQuery
    end alfred_script

     

  10. set myComment to "xxxx@boards.trello.com"
    set theName to "Some name"
    set theAddress to "Some email address"
    set mySignature to "blank"
    
    
    try
    	set the clipboard to myComment
    	tell application "Mail"
    		set theSelection to selection
    		set theForwardedMessage to forward (item 1 of theSelection) with opening window
    		tell theForwardedMessage
    			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
    		end tell
    		activate
    		tell application "System Events" to keystroke "v" using {command down}
    		delay 1
    		
    		try
    			set message signature of theForwardedMessage to signature mySignature
    			
    		on error --BUG SIERRA 
    			
    			tell application "Mail" to activate
    			tell application "System Events"
    				tell process "Mail"
    					click pop up button 4 of window 1
    					delay 0.1
    					keystroke "b" --put here the first letter of the name of your signature 
    					delay 0.1
    					keystroke return
    					delay 0.1
    				end tell
    			end tell
    			
    			
    		end try
    		
    		-- send theForwardedMessage
    	end tell
    end try

    this worked for me (commented out the send for testing)

     

    this requires that you have a signature called "blank" that's active in the sending account

  11. Here's how I'd do it:

     

    create a Hotkey with Selection in MacOS as argument

     

    pipe that to a bash script object containing the following script:

     

    query=$1
    
    echo "$query" | tail -r

    pipe that out to a Copy to Clipboard object, optionally setting it to paste to the frontmost app

     

     

    ....but this isn't going to capture HTML/rich styling or images.  If Evernote lets you view the HTML source, you could select the source and run the same script - that would handle your images, then you'd need to run some other code to clean the HTML tags so the open and closing tags aren't flipped (there's the trick with HTML -- you're reversing the content, but the order of the tags actually needs to stay the same & not be reversed).

  12. It looks to me like this is a bug in AppleScript (on Sierra at least).  I tried a handful of Mail signature creation scripts and experimented with yours and none of them are working.  See also https://gist.github.com/Moligaloo/3850710 .  With Sal gone I fear it may never get fixed.

     

    But....Mail Act-On Outbox rules do work, so presumably they're accessing the signature some other way.  It's $30 but if you work with a lot of email it's worth it IMHO.

×
×
  • Create New...