[FIXED] To invoke Hook window in Ulysses one needs to select the doc in the Sheets column (not put the focus in editor). A bug with Ulysses

#1

We at CogSci Apps added support for Ulysses in build build 2115 per [DONE] Any possibilities for Ulysses integration? - Hook Feature Requests - Hook Productivity Forum. However, it doesn’t work for @quorm . I’m starting this bug report thread to track this problem. Here is the problem as reported so far:

None of us uses Ulysses for production work here at CogSci Apps. So maybe the issue only comes up with enough (variety of) content in Ulysses.

Is anyone with a large Ulysses database using Hook successfully with it? We’ll create a large, varied number of docs (if our developer hasn’t already), and investigate further.

[DONE, but investigating issue] Any possibilities for Ulysses integration?
#2

just to be sure: @quorm could you please confirm that the bottom of the Hook > Preferences > Script Editor tab shows Version 23 as the latest script version?

Also, if you added a custom Ulysses script, that could be the cause of the problem. I would recommend deleting it from Hook, and then updating your scripts (via the Script Editor tab). (The keyboard shortcut to get to the Preferences window is ⌘, (as is typical).)

When Ulysses first launches, it does not fully select a document, so Hook comes up blank (no resource detected). I need to click on a document to select it, then Hook window is populated as expected.

I’ve tested with Ulysses Version 15 (48292) from SetApp. We also have a script for the standard (non-setapp) version of Ulysses.

#3

@quorm A developer of ours also noted that Ulysses has its own authentication scheme (there’s code for it in Hook’s “get address” script). We’ll be looking into that as a potential source of the issue. We’ve tested with SetApp and the Mac App Store version of Ulysses.

#4

We have investigated, here is what we have found:

There is a bug in Ulysses with the keyboard command for “Copy Callback URL” preventing it from being called from the Editor column. Because of the bug, Hook won’t work with Ulysses when the editor column is selected.

We’ve reported the bug to the developers of Ulysses, hopefully they’ll fix it soon. In the meantime, you can work around the issue by selecting the document in the Sheets column (on the left) before invoking Hook.

Basically, when the selection on the left is grey, the Editor column is selected and Hook will not work, but when it is blue, Hook will work with it. See the image below:

#5

Selecting the document in the Sheets column is what I have done in all the tests I have done with various versions of Hook and Ulysses 14 and Ulysses 15. Every time there is a failure. So, using the Sheets column is not the fix.

Your script basically uses UI scripting to mimic keypresses, etc. (In fact that’s what I suggested a long time ago.) The problem is, that UI scripting is probably the most fragile way to control an app and is entirely dependent on factors local to the users’ machine. It’s possible I have some utility that conflicts with your UI script for Ulysses. It’s possible that there’s no way that can be discovered.

I’ve given up on the Hook/Ulysses integration as not possible, due to limitations in Ulysses scripting capabilities, so you can drop my name off the users who want the feature.

#6

Thanks for the update. Still, hopefully the Ulysses developers will oblige by providing the couple of AppleScript functions needed to get the address and name of documents.

#7

Update: I got another reply from Soulmen’s, the developers of Ulysses. They stated that due to their big task list, “for the time being, it is not planned to integrate such an API”. They also did not indicate that they would fix the bug with their x-callback-url. At least Ulysses users have a work-around (selecting the document in the Ulysses).

For the growing list of apps known to be compatible with Hook, please see this web page, which includes writing apps such as nvALT, Agenda, Bear, Drafts, Scrivener, Pages, etc. We are quite pleased to support such great writing apps. I’m quite excited about upcoming developments in the automatable Mac writing app space :wink: .

#9

That seems to be the most reliable way. In that case, the document name is lost. In the future, however, Hook will likely enable users to rename links.

I’ve published a video on youtube that demonstrates that

  1. I can invoke a functional Hook window by selecting a document in the middle (“sheets”) column. In that case, I can link the Ulysses doc to a new doc; those links work in both direction. Also, the links are properly named (with the document names). (I also separately tested “Copy as Link”, “Link to Copied Address”, which is not demonstrated in this video).
  2. when selecting the document pane on the right, Hook is not presented (for reasons to do with Ulysses’s x-callback-url response).

Whether the Hook window is presented or not, I often experience a latency between issuing the Hook keyboard shortcut and the Hook window being presented. The video is edited for conciseness, but I a made a note of this in the description of the video itself.

Hopefully the Ulysses developers will soon see the value of providing AppleScript or JavaScript support. That would allow better automation with other tools (like Keyboard Maestro, Alfred and LaunchBar).

As a corollary of this, drag and drop linking on menu bar icon doesn’t work with Ulysses.

#12

I’ve got a working AppleScript but it’s not pretty. Add this below ‘-- wait until shift key isn’t held down’ and above ‘-- get item ID’ in the built-in Hook handling:

– select Sheets column
tell application id “com.ulyssesapp.mac”
activate
tell application “System Events”
keystroke “3” using {command down}
key code 123 using {option down, command down}
end tell
end tell
delay 0.7

#13

That works @stevelw. The response is so deathly slow, unfortunately, that I wouldn’t want to use Hook with Ulysses very often if this is the only solution.

#14

I found a delay of 0.5 works on my system (30% faster response) but I put it up to 0.7 to make it more robust.

Try lowering it and see if that helps.

#16

OK, I got it running, and fixed my error of not allowing you to link to a group in Library. Does this work for you?

Add this below ‘-- wait until shift key isn’t held down’ and above ‘-- get item ID’ in the built-in Hook handling:

-- Select Sheets or Library
tell application "System Events"
	tell process "Ulysses"
		if enabled of menu item "Clear Markup" of menu 1 of menu bar item "Markup" of menu bar 1 then
			-- Editor selected
			-- Select Sheets view
			-- 123 = left arrow key
			key code 123 using {option down, command down}
		else
			-- Editor not selected
			if not enabled of menu item "Reveal in Group" of menu 1 of menu bar item "File" of menu bar 1 then
				-- Attachments selected
				-- Select Sheets view
				key code 123 using {option down, command down}
				key code 123 using {option down, command down}
			end if
			-- Attachments not selected
			-- else Sheets or Library selected already
		end if
	end tell
end tell
[DONE, but investigating issue] Any possibilities for Ulysses integration?
#17

I see the above has been added to the built in script. In my experience I have had to add the below delay to get it to work reliably — a smaller delay is probably sufficient, but this is what I ended up with.

key code 123 using {option down, command down}
delay 0.5
key code 123 using {option down, command down}
#18

Here’s an alternate approach which I think we’re going to use

-- Select Sheets or Library
tell application "System Events"
	tell process "Ulysses"
		repeat 50 times
			if not enabled of menu item "Reveal in Group" of menu 1 of menu bar item "File" of menu bar 1 then
				key code 123 using {option down, command down}
			else
				exit repeat
			end if
		end repeat
	end tell
end tell

It might seem crazy to mash ⌥⌘← (up to) 50 times, but the advantage of this is that it doesn’t depend on delays which will be unnecessarily long on some users’ systems and too short on others.

#19

Does this not risk over-shooting and getting the link to the Library item, not the sheet, ending up creating a link to the wrong thing?

#20

Unfortunately nothing is totally safe when you’re doing UI scripting, but I think this is as good as we could hope for.

To overshoot and go from Editor to Library there would have to be a race within Ulysses checking if “Reveal in Group” menu item is enabled, in the middle of handling a keypress. The check would have to take place after Ulysses has received the keypress and started handling it but before it finishes and enables the “Reveal in Group” menu item

I can’t know how Ulysses is implemented, but I expect both of those to happen on the main thread, so they would happen in sequence, and this would be impossible.