Monday, July 26, 2021

#1 2021-06-15 05:37:16 pm

scottm
Member
Registered: 2013-04-05
Posts: 4

How do I fix this error message?

Hi, all,

I've been successfully using the AppleScript listed below for quite a while, but all of a sudden it has broken with the attached error message (RetinaError message)

I'm running Big Sur 11.4 on a 2020 iMac 27.

I have searched the forums for "SPDislaysDataType" and "shell script retina" with no success, so I'm hoping it's a recognizable error which someone can explain a correction for.

If this is a common issue that has been addressed many times, a suggestion about what to search for and/or how to find it would be appreciated.

Or, if anyone has suggestions as to how to improve on the script, I'm all ears. The purpose of the script is to create one Finder window of a specific size and in a specific location each time the computer reboots.

Thanks for your time,

Scott

P.S. I have a 27" monitor attached to the iMac.

set monitorWidth to (word 2 of (do shell script "system_profiler SPDisplaysDataType | grep Resolution")) * 0.9
set monitorHeight to (word 4 of (do shell script "system_profiler SPDisplaysDataType | grep Resolution"))
delay 5
tell application "Finder"
    get the number of Finder windows
    set winNum to the result
    if winNum is greater than 1 then
        repeat until winNum is equal to 1
            close Finder window winNum
            set winNum to (winNum - 1)
        end repeat
    end if
    if winNum is equal to 0 then make new Finder window
    -->set bounds of Finder window 1 to {15, monitorHeight * 0.6, monitorWidth, monitorHeight}
    set bounds of Finder window 1 to {730, 860, 2516, 1424}
    set the target of the front Finder window to folder "V" of folder "W" of folder "X" of folder "Y" of folder "Z" of startup disk of application "Finder"
end tell

Last edited by scottm (2021-06-15 05:38:51 pm)

Offline

 

#2 2021-06-15 06:11:42 pm

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

Re: How do I fix this error message?

Scott. Your script works fine for me but I'm on Catalina. I suspect the issue arises from the output of system_profiler and the use of word 2 and word 4. To troubleshoot, run the following line in script editor and look at the results.

Applescript:

do shell script "system_profiler SPDisplaysDataType | grep Resolution"

I get the following, so word 2 and word 4 work OK. My guess is that you'll see something different.

"          Resolution: 3840 x 2160 (2160p/4K UHD 1 - Ultra High Definition)"



If the above doesn't resolve the issue, you may want to try the following, which also works on Catalina:

Applescript:

delay 5 -- test different values

tell application "Finder"
   set theBounds to bounds of desktop's container window
   set monitorWidth to item 3 of theBounds
   set monitorHeight to item 4 of theBounds
   
   set winNum to the number of Finder windows
   if winNum is greater than 1 then
       repeat until winNum is equal to 1
           close Finder window winNum
           set winNum to (winNum - 1)
       end repeat
   end if
   if winNum is equal to 0 then make new Finder window
   -- set bounds of Finder window 1 to {15, monitorHeight * 0.6, monitorWidth, monitorHeight}
   set bounds of Finder window 1 to {730, 860, 2516, 1424}
   -- set the target of the front Finder window to folder "V" of folder "W" of folder "X" of folder "Y" of folder "Z" of startup disk of application "Finder"
end tell

BTW, it doesn't appear that you use the monitor width and height in the script, because the line that would use these values is commented out. The following is an informative thread on getting screen resolution:

https://macscripter.net/viewtopic.php?pid=203998

Last edited by peavine (2021-06-16 09:29:06 am)


2018 Mac mini - macOS Catalina - Script Debugger 8

Offline

 

#3 2021-06-16 09:30:01 am

scottm
Member
Registered: 2013-04-05
Posts: 4

Re: How do I fix this error message?

run the following line in script editor and look at the results.


Open this Scriplet in your Editor:
do shell script "system_profiler SPDisplaysDataType | grep Resolution"



Thanks, peavine, for the quick response! That worked perfectly.

BTW, it doesn't appear that you use the monitor width and height in the script, because the line that would use these values is commented out.



Yes, I commented it out while trying to figure out the problem and then forgot to uncomment it. And thank you for the alternate method of coding this... I haven't had a problem yet, but will try this out to see if it improves the operation.

Again, thank you for the assistance!

Scott

Offline

 

#4 2021-06-17 08:10:34 am

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

Re: How do I fix this error message?

Scott. You're welcome. I'm glad that got things working.

Just in case anyone else happens upon this thread with a similar issue, I thought I would add a quick note concerning display resolution. The system_profiler utility returns two values, which on my computer with a 4K monitor are quoted below. In contrast, desktop's container window property returns what is effectively the UI-looks-like value. There's no absolute right or wrong about this but, if the values differ, I would use the looks-like value when setting the bounds of a window.

Resolution: 3840 x 2160 (2160p/4K UHD 1 - Ultra High Definition)
UI Looks like: 1920 x 1080 @ 60 Hz



It's also worthy of note that the system_profiler utility is relatively slow. In testing with Script Geek, the system_profiler utility with grep took 180 milliseconds to run, while getting desktop's container window property took 22 milliseconds. ASObjC's NSScreen's frame property took only 3 milliseconds, although this assumes that the AppKit and Foundation frameworks are in memory.

Applescript:

-- requires macOS 10.0 +
use framework "AppKit"
use framework "Foundation"
use scripting additions

set screenFrame to current application's class "NSScreen"'s mainScreen()'s frame()
--> {{0.0, 0.0}, {1920.0, 1080.0}}

Last edited by peavine (2021-06-17 09:30:53 am)


2018 Mac mini - macOS Catalina - Script Debugger 8

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)