[fixed with 3.0 compiled universal/ M1+intel] Preview.app not working [for some M1, Big Sur customers]

@tedsvo and @racemase . It may be that macOS permissions for Preview got corrupted on your Mac (that happens, not
due to Hook). You could try this:

  sudo tccutil reset All com.cogsciapps.hook

That will reset all of Hook’s access for all apps. You’ll need to give permission for any app that you want to use Hook with.

See also:

Hi Luc, I did this and restarted Hook and it asked me to reauthorize Accessibility, as well as grant permissions in each app I tried to invoke it in. When I tried to invoke it in Preview, Hook beachballed for a minute or two and then asked for permissions to control Preview. When I granted it it said no linkable item found, and now it’s back to stalling and doing nothing when I invoke it in Preview. I have to quit Hook from Activity Monitor to be able to use it again.

Fwiw I’m not running 11.3, and the problem hasn’t changed.

I’m also using M1 Mac and preview also doesn’t work for me as well. I also had a impression that the app just stuck for a minute when I was trying to give permission.

Thank you @tedsvo for your console output file.
(1) Could you please restart the machine after run the following command and see if it helps? Ignore this if you have done so.
sudo tccutil reset All com.cogsciapps.hook
(2) Could you please run the following command in /Applications/Utilities/Script Editor and send us the result?

tell application "Preview"
	set fpath to path of front document
	#tell application "System Events" to set myFileUrl to URL of fpath
	set escapedfpath to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of fpath
	return "file://" & escapedfpath
end tell

Thank you

Hi,

so, I’ve updated my M1 MBP to 11.3 and still had the issue. I then restarted my machine and reset the permissions by running the shell command. After invoking hook within Preview it beachballed for almost two minutes, then asked for permissions and after granting them it showed “No linkable item”. This ist new. Before it just did nothing. So, I had the “No linkable item” before, with UI skripting Soulver as I run a German macOS. But as far as I understand, here it’s Apple Script and the different name of the application (Vorschau instead of Preview) should not be an issue. As noted, it run fine before on my non M1 MacBook on 10.15 (?).
I run the script in Script editor and the output is the path and filename of the opened pdf: “file:///Users/myusername/Downloads/Reparaturauftrag_2018-01-05.pdf”

I have never used the Console App and struggled a little but I will try to send you the output I’ve received privately.

Kind regards

Marco

FYI, we have been working behind the scenes (with some PMs) to isolate the issue. We thought it might be a cache problem (as that can sometimes affect AppleScript), but that hypothesis was refuted.

We’re now looking into whether on some Big Sur installations, the use of a python by a non-Apple app (viz. Hook) may be causing issues. [Script Editor is not bothered by it]. So we’ve replaced that bit of code for some to try to see if it’s an issue.

We’ll report back later.

Hi Luc,

thank you very much for all your hard effort you put into finding the cause of this bug that most probably does not even lay on your side. As you mention Python I have one additional remark. Yesterday, I’ve upgraded my non-M1-MacBook Pro to Big Sur 11.3 and there hook works still flawlessly with Preview. From what I can tell there are two main differences between those to machines / installations: The first one is obviously the other chip (Intel vs. Apple Silicon), the other is homebrew. On the M1-Mac I do run brew and python@3.9 was installed as a dependency of one Formulae. Could this cause a problem? As Preview is the only app so far I have problems with, is there an easy way for me to find out which other apps might be affected by your use of python, I could try and see if these make problems as well? (DevonThink, Excel, Word, Numbers, Pages, Finder, Safari, etc. all work fine.)

Kind regards

Marco

1 Like

Just a short follow-up: I went through the list of Get Address scripts and found only nvUltra with some “python” stuff in it. Hook and nvUltra play fine together …

1 Like

I think it is primarily some problem cause by the different chip. I don’t run homebrew on my m1 Mac.

Hi @bchend - I already did the restart/reset permissions, and after granting Preview permissions the problem persisted.

The script runs totally fine in Script Editor. It just returned a URL to the PDF:

“file:///Users/tsvoronos/Documents/Voting%20Rights%20Act/app.20170572.pdf”

A quick follow up. We are sorting through the console and other reports. In one user’s case, the Console.app output shows that Hook does not have permission to access Preview:

error 09:32:12.182329-0700 Hook Failed to get url error:“NSAppleScriptErrorMessage” = “Not authorized to send Apple events to Preview.”;

So it looks like in that case for whatever reason granting Hook permission to control Preview failed. This might be a macOS glitch. It may be that rebooting would help. That would explain why Script Editor works for said user.

Another user’s issue seems different.

we’re doing some of the communications through PM’s, partly to avoid console logs being public.

Preview now works for me after updated to 3.0. I’m not sure if it is caused by the new update or previously I changes some scripts.

Hook 3.0 did not change the Preview scripts. It was a strange issue that was not caused by Hook and only showed up on M1 Big Sur, I think. I strongly suspect this works because we compiled Hook 3.0 for M1 (Universal: Intel, Apple Silicon). (It’s not supposed to make a difference but the issue is low level macOS security stuff opaque to Hook. So it looks like this would be the fix.)

If this is the case it means that compiling for M1 can have functional effects for users, meaning Rosetta 2 is not perfect.

This problem seems to be resolved for me with Hook 3.0! Interestingly when I invoked it, it actually asked for permission to access the folder the PDF was in (as opposed to automation access for Preview which is what I had been obsessing over).

Regardless, it seems that my long Preview nightmare is over!

1 Like

JFYI works for me now, too :grinning:

1 Like