Catalina and AppleScript

My Xojo app calls a little AppleScript that opens a PDF in the application the user selects (e.g. Preview). This is broken in Catalina. This AS that works in Mojave, for example, fails (I’m running it in Script Debugger, not Xojo, btw):

tell application “Preview”
open file “/Users/myusername/Desktop/test.pdf” as POSIX file
end tell

Although the file exists, the error is

 The file "/Users/myusername/Desktop/test.pdf" couldn't be opened because there is no such file.

Removing the “as POSIX file” doesn’t help. This error occurs with all applications, not just Preview, and being on the Desktop is irrelevant (the file can’t be found no matter where I put it).

This is not a privacy/permissions thing. Preview gets the AppleEvent and activates – and the error is returned from Preview. I have other AS that work fine, this one does not.

Any idea what is going on, and what the correct syntax should be for Catalina?

To answer my own question:

The syntax has become more strict in Catalina – removing the “file” reference works:

open “/Users/myusername/Desktop/test.pdf” as POSIX file

[quote=457228:@Jonathan Ashwell]To answer my own question:

The syntax has become more strict in Catalina – removing the “file” reference works:

open “/Users/myusername/Desktop/test.pdf” as POSIX file[/quote]

Thanks for sharing the information, I have a question for you, where did you get this information, do you have any kind of documentation you found because I have lots of AS I use and I may have to change some things too.

I’m afraid I stumbled on it by trial and error. There is very little information out there that I could find on AS and Catalina.

Care to explain why you use AppleScript to load a pdf (instead or FolderItem.Launch ?

And there is an example to do just that.

I do use FolderItem.launch when user wants to open the PDF in his default PDF reader. But when they want to open the PDF in a specific app (e.g. Preview, Adobe Reader, PDF Expert, etc.) I use an AppleScript. I’m not aware of a native Xojo method for that. It’s trivial with an AppleScript.

Yes, you are right at 100%.

BUT: if the user have a preference, it is his duty to set the default pdf application to the one (s)he want. Isn’t it ?

I know another app that does something like this to provide previews in one of many installed web browsers
And there is no built in way to do that so you either use applescript or mbs or declares

Set the default the Finder via Get Info? Sure they can. But that’s not particularly friendly or intuitive. In our app they can set a preference to use the Finder Default or any of the PDF viewers we support by selecting a “open PDF” option. In addition, they can open a PDF in any of these viewers ad hoc via a hierarchical menu choice. Our users make extensive use of this flexibility.

Maybe not in the default Xojo toolset, but it can be done with Declares or Plug-ins, and I seem to recall even with the command line. I would personally recommend investigating another solution as Apple Script can be disable by the user on Catalina, they’re asked if they want to allow your app to use Apple Script without given any context as to what for. If they choose deny, your application will lose this functionality.

IMHO, the writing has been on the wall for Apple Script for a while now, I would label it unofficially deprecated.

After reading our explanation, I love it.

But you work against the OS doing so.

As an example, let’s talk about the default browser:
when yourdefault is not the one you fire, the actual application (at load time) check who’s the default one and ask you if you want to change that (there is even a preference setting to ask or not at launch time).

OK: boring, but you only have to make the change once (if you want that).

Now, you are OK with what you have and so your users ? Who am I to tell you “You have to make changes!” ?

PS: my default pdf reader is… Preview. Sometimes, for specific reasons, I fire Acrobat Reader. So…

I’m using a simple script to open Finder and show a file location:

tell application "Finder" set ThisFile to POSIX file "myfolder/myfile.jpg" reveal (ThisFile) as text activate end tell
The script works fine at Script Editor (had to change “reveal POSIX file XX as text” to current) but not using AppleScriptMBS in Xojo, it raises error -1753 and empty result.

I can script other applications without problems (open files, transform, etc).

Is there any restriction to script Finder in Catalina I should know?


AppleScriptMBS is the old way of. NSAppleScript is newer.
Scripting Finder isn’t a good idea. Use NSWorkspaceMBS.selectFile .

Check out lots of other posts on Mojave and AppleScript.

Thanks so much Beatrix, this solved my issue.

[quote=457555:@Sam Rowlands]
IMHO, the writing has been on the wall for Apple Script for a while now, I would label it unofficially deprecated.[/quote]

But there is such a large userbase of mission-critical business installations which use AppleScript. There would be an uproar if Applescript were to cease to exist.

No, people will search a replacement as fast as they can.

Remember the lack of love AppleScript get all those years: nearly no reaction.

I agree with you, I see no reason to end AppleScript, I use a lot of them for my Apps and today I have no way to change it, as well as Photoshop and Ilustrator Plugins, and a lots of AS-based graphics programs.

Let me explain:

  • The first entitlement you can use to call Apple Script, was marked as temporary from the start. It was only a stop gap solution until the newer one was ready. You can’t distribute a new application on the Mac App Store with this entitlement, technically you might get a reviewer who actually cares and can argue that it’s needed.
  • The second entitlement, the one you should be using is useless. Take Mail for example, use the Temporary entitlement and it works. Use the newer one, and all you can do is create a new e-mail (which you can do using many different API).
  • It appears that hardened applications now require entitlements for macOS 10.15 Catalina (I’ve not verified this myself).
  • I don’t doubt that Apple Script will live on longer as a User scripting system, but IMHO, this drive on Security is going to remove it eventually for developers.
  • Catalyst apps don’t (probably won’t) have Apple Script support, and I’m 100% confident that a future version of the macOS will only run Catalyst apps.

This is of course my personal opinion, based upon what I’ve seen over the past 8~9 years.

@Sam Rowlands :

Yup. I wasn’t able to get AppleScript to work for the MAS version at all. For Mail the entitlements are useless.

Nope. Hardened apps can use AppleScript - there is no difference to Mojave.

Catalina seems to fix the bug in AppleScript that has plagued me since High Sierra. If you had too many AppleScripts then the Mach ports were used up until you had to reboot the computer.