Sunday, July 3, 2022

#1 2022-03-17 10:21:06 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 86
Website

"The application "Preview" can't be opened -1703"

In my applet, I have a small amount of code which displays a user guide which is in pdf format. The user guide is inside the applet's resources folder.  The pdf file is printed from Apple Pages.

The code has been in much the same form for 3 years.  It has been in this form for 12 months:

Applescript:

set path_to_applet to path to me as text
set path_to_applet_alias to path_to_applet as alias
set applet_help_file to (path to resource "Help.pdf" in bundle path_to_applet_alias) as string
tell application "Finder"
   open file applet_help_file
end tell

I've recently noticed that when running the applet in another language (French as it happens), it would produce an error:

"'The application "Preview" can't be opened"

[I wish I could show a capture of the error here but, I can't get img tags to work with files shared from Box].

Today, now, I get the error in English as well.

I get this error in macOS 12.3 but no other version of macOS.  I have tested in macOS 10.13, 10.15 and 12.2.1 – no error.

Has anyone experienced such odd behaviour in macOS 12.3 ? Any ideas as to the cause ?

Thanks.


UPDATE: New behaviour now.  Instead of showing the error nothing happens at all.  SD8 runs the code but usually Preview doesn't open and SD8 doesn't report a result.  Sometimes, Preview opens but does not open the pdf file.

Last edited by Neophyte (2022-03-17 10:27:23 pm)


Public servants are people too
Mac Studio M1 Max 24c, 32GB, 1TB; Studio Display; macOS Monterey, 12.3.1

Offline

 

#2 2022-03-18 12:59:06 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6779

Re: "The application "Preview" can't be opened -1703"

I wonder if this is part of the issue reported here:

http://piyocast.com/as/

Roughly translating:

At the moment, if you let the Finder open the file from AppleScript on macOS 12.3, the phenomenon that "creator's application starts, but the file will not open" It seems that it is occurring (some cases where an error dialog appears or there are cases where it does not appear), and it seems that it is not consistent


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2022-03-18 02:23:43 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 958

Re: "The application "Preview" can't be opened -1703"

Here is something you could try:

1. We type in terminal: open -a "Preview"
(it will open a dialog for a user to pick a file) ---> OK

2a. We will add a pdf file as argument open -a "Preview" --args 'path_to_file'
(it will open the file) ---> OK

2b. Lets do it again but change the open option to use bundle identifier instead
open -b "com.apple.Preview" --args 'path_to_file' ---> OK

3 Lets only use open 'path_to_file'
I guess this will use the default application

So you could try this if that makes any difference or to isolate the problem if its a Finder issue.
You could also try to use System Event instead of Finder.

Applescript:

set path_to_resources to POSIX path of (path to me) & "Contents/Resources/"
do shell script "open -b 'com.apple.Preview' --args '" & path_to_resources & "Help.pdf" & "'"

Last edited by Fredrik71 (2022-03-18 02:35:22 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#4 2022-03-18 05:09:29 pm

hubert0
Member
From:: East Anglia
Registered: 2020-11-20
Posts: 42

Re: "The application "Preview" can't be opened -1703"

After updating to 12.3 with some trepidation, the following works for me:

Applescript:

do shell script "open " & quoted form of POSIX path of ((path to me as text) & "Contents:Resources:help.pdf")

The help file opens infallibly in Preview, which is set as my default app for opening .pdf files.

But the following also seems to work without issue:

Applescript:

set path_to_applet to path to me as text
set path_to_applet_alias to path_to_applet as alias
set applet_help_file to (path to resource "help.pdf" in bundle path_to_applet_alias) as string
tell application "Finder"
open file applet_help_file
end tell

Again, the help file opens in Preview.

Both scripts were created, compiled and saved using Script Editor v 2.11. Running macOS Monterey 12.3 on Intel 64bit.

The name of the help file is case sensitive, but if I get the case wrong I get 'missing resource' errors rather than problems opening Preview.

¯\_(ツ)_/¯

Last edited by hubert0 (2022-03-18 05:12:45 pm)


MacOS 11.0.1

Offline

 

#5 2022-03-18 05:57:12 pm

hubert0
Member
From:: East Anglia
Registered: 2020-11-20
Posts: 42

Re: "The application "Preview" can't be opened -1703"

hubert0 wrote:


But the following also seems to work without issue:
-snip-
¯\_(ツ)_/¯



Yeah but... I've been testing my second script (the OP's original) repeatedly and I do sometimes find that Preview launches but the file doesn't open. I wonder if it's down to timing. The following may work better if you always want Preview to open the file, even if it isn't the user's default app for opening pdfs:

Applescript:

set path_to_applet to path to me as text
set path_to_applet_alias to path_to_applet as alias
set applet_help_file to (path to resource "help.pdf" in bundle path_to_applet_alias) as string
tell application "Preview"
   activate
   open file applet_help_file
end tell

Last edited by hubert0 (2022-03-18 05:59:34 pm)


MacOS 11.0.1

Offline

 

#6 2022-03-18 09:44:35 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 86
Website

Re: "The application "Preview" can't be opened -1703"

There are more reports of a problem peculiar to macOS 12.3:

https://news.i-n24.com/technology/107246.html

Scroll down for the snippet – reported by the makers of Keyboard Maestro.

It is looking like a bug as it has changed for me.  Started only occurring in another language then after a day or so, started happening in English.  Maybe related to caching or something that happens over time ?

I've started making a clean macOS 12.3 VM in which to do some testing.  But, probably, the solution for me will be to use a "do shell script" method in background to get around the issue.


Public servants are people too
Mac Studio M1 Max 24c, 32GB, 1TB; Studio Display; macOS Monterey, 12.3.1

Offline

 

#7 2022-03-19 04:00:11 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 958

Re: "The application "Preview" can't be opened -1703"

If its a Finder issue you could also try.

Applescript:

tell application id "com.apple.Preview" to open applet_help_file


if you are the expert, who will you call if its not your imagination.

Offline

 

#8 2022-03-19 06:37:34 pm

Neophyte
Member
From:: Canberra, ACT, Australia
Registered: 2017-08-20
Posts: 86
Website

Re: "The application "Preview" can't be opened -1703"

This is becoming a pain.  At first, his morning after a cold boot, I could not get the problem to surface.  My current code worked.  Also, this code worked:

Applescript:

tell application "Finder" to open applet_help_file

Now, after working properly a few times, that code opens Preview but doesn't open the target pdf file.  But, both of Fredrik71's suggestions still work every time i.e. using "System Events" instead of Finder and calling Preview directly.

I don't understand why the problem would be intermittent.  Anyway, I guess it's prudent to assume it will always occur and add code specifically for macOS 12.3 or just switch to System Events.

Many thanks.


Public servants are people too
Mac Studio M1 Max 24c, 32GB, 1TB; Studio Display; macOS Monterey, 12.3.1

Offline

 

#9 2022-03-19 07:00:14 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1370

Re: "The application "Preview" can't be opened -1703"

Neophyte wrote:

This is becoming a pain.



Fredrik71 has provided two working solutions, and I provide an ASObjC solution FWIW.

Applescript:

use framework "AppKit"
use framework "Foundation"
use scripting additions

set path_to_applet to path to me as text
set path_to_applet_alias to path_to_applet as alias
set applet_help_file to (path to resource "Help.pdf" in bundle path_to_applet_alias)
openFile(POSIX path of applet_help_file)

on openFile(thePath) -- thePath is POSIX path
   set theWorkSpace to current application's NSWorkspace's sharedWorkspace()
   set theURL to current application's |NSURL|'s fileURLWithPath:thePath
   theWorkSpace's openURL:theURL
end openFile

BTW, if I correctly understand the dictionary entry for "path to resource", the "in bundle" property does not appear to be necessary with the OP's script.

Applescript:

set applet_help_file to (path to resource "Help.pdf")
tell application "Finder" to open applet_help_file

Last edited by peavine (2022-03-20 09:31:59 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#10 2022-03-22 03:52:46 am

alitaliano
Member
Registered: 2010-10-12
Posts: 35
Website

Re: "The application "Preview" can't be opened -1703"

Hi all, thanks for your help.
Indeed, it seems there is a problem related to MacOS 12.3.

The script :

Applescript:

tell application "Finder" to open file aFile using application file anApp

doesn't work either…

Last edited by alitaliano (2022-03-22 02:33:40 pm)

Offline

 

#11 2022-03-25 05:43:29 pm

OwlBoy
Member
Registered: 2007-04-26
Posts: 1

Re: "The application "Preview" can't be opened -1703"

Hello! The last time I was logged into this forum was in May of 2007! Anyway…

I am getting the same error with Unity when Unity tries to tell another application to open a file. Be it Unity->Blender or Unity->Photoshop.

I also found someone online saying it is an error happening when Photoshop tries to tell Illustrator to open files.

And now I see here that scripts are having the same issue. I just wanted to drop in a note saying this is indeed an issue with 12.3 and goes beyond AppleScript. I just updated to 12.3 and it started.

-OwlBoy

Model: iMac Pro
Browser: Safari 605.1.15
Operating System: macOS 12

Last edited by OwlBoy (2022-03-25 05:45:42 pm)

Offline

 

#12 2022-03-27 02:42:33 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 958

Re: "The application "Preview" can't be opened -1703"

OwlBoy wrote:

...error happening when Photoshop tries to tell Illustrator to open files.


Maybe I misunderstood, but having other app's tell block inside a tell block of a application can be
difficult to debug or be confusing if its a bug or conflict with the implementation of the terminology of the scriptable application.

In other words its not Photoshop that tell a scriptable application to open a document.


if you are the expert, who will you call if its not your imagination.

Offline

 

#13 2022-04-01 01:14:04 pm

dfbills
Member
Registered: 2007-09-29
Posts: 5

Re: "The application "Preview" can't be opened -1703"

Looks like this issue was fixed with yesterday's macOS 12.3.1 (21E258) release.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)