My new favorite way to write (this week)

It’s amazing how easy it was not to see that—so, many thanks for pointing it out! It would be a good way of working with edit/preview in a large markdown file on a MacBook Pro screen, where the existing side-by-side view is a little constrained at times.


1 Like

Could you please include the code parts in your post in backticks like so (after lunch, of course)
`code goes here`
That would take care of the formatting issues we’re seeing now (like the sed command making no sense at all)
Thanks a lot.

Not sure you’re going to be much happier - that is close to what the sed command looks like in the script.

Sed is great. I don’t use it often enough to stay current, but I use similar regex syntax in Python all the time.

I see I left head -n 1 in the script, which was something I added to try to help.

From a re-install of the script, here are the lines causing trouble. The sed command is not stripping out what it should:

set displayRes to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | sed -E 's_.* ([0-9]*) x ([0-9]*)_\\1 \\2'_")

set {w, h} to {word 1, word 2} of displayRes

displayRes is getting set to:

Resolution: Retina 5K (5120 x 2880)
1920 1920 (1080p FHD - Full High Definition)

w and h are ending up as Resolution and Retina, not pixel dimensions.

One thing that’s not causing trouble but might bear editing is the end of the sed string is:

...\\1 \\1'_

It would be a little more standard to have the trailing underscore search delimiter inside the single quote. I assume AppleScript eats a backslash.

And, now, I’m getting pinged for work. Sigh.

The output of the grep is:

Resolution: Retina 5K (5120 x 2880)
Resolution: 1920 x 1080 (1080p FHD - Full High Definition)

Sed is catching the last 1920 x 1080 and stripping out the “x”, leaving the first display’s resolution specs untouched.

One workaround is to set {word 1, word 2} to {word 4, word 6}, but that seems like a copout.

More if I can get the time. It’s going to be one of those weekends.


I updated MacOs, removed and installed the script again. Docs were opened but not side-by-side. Maybe the script needs to be updated. I am using a MacBook Air (Retina, 2019).

I think sed’s behavior changed somewhere along the line.

You’re welcome :slight_smile:

Running the code and returning the sed on the resolution is yielding the expected results.

I am seeing there is a strange issue with the divisor variable.
I have a conditional checking for Retina in the profiler output. The M1 doesn’t report it’s a Retina screen though it is.

Even stranger - from my M1 Air.

Then look at the return from the system_profiler

apollox@ApolloX ~ % system_profiler SPDisplaysDataType | grep Resolution | sed -E 's_.* ([0-9]*) x ([0-9]*)_\1  \2_'
2880  1800

Note there is a discrepancy in the width.

It wouldn’t be the cause of the particular issue but something strange is afoot.

Then there is some difference in the output of system_profiler - although I still think sed is behaving differently on my system:

% system_profiler SPDisplaysDataType | grep Resolution | sed -E 's_.* ([0-9]*) x ([0-9]*)_ _'
Resolution: Retina 5K (5120 x 2880)
(1080p FHD - Full High Definition)

I’m not seeing what you’re seeing. That is a cut and paste from Terminal - the sed command was a cut and paste, the output is two lines of text, not two numbers.

Weird, isn’t it?

I suggest that you amend your regular expressions to include everything after the second capturing group as well. Something like
I used ! instead of _ (for readability) and \s+ instead of just a blank.

Also, the final .* should gobble up everything after the second number. If that expression gets you the correct resolution? No idea. At least it shouldn’t get you too much.

As you told it to: .* at the beginning grabs as much as it can (!) until it finds the second (!) „Resolution“. You should use a non-greedy .*? if that’s what you want.

Chrillek, thank you for your time. I see that greediness issue. It’s not my script, so I’m a newcomer to it.

One thing I also see is that I need to rediscover sed. I use regular expressions constantly, often daily, in Python.

Speaking of which, I changed the “do shell script system_profiler…” to:

set displayRes to (do shell script "~/Documents/bin/") contains:


import os, re

resRe = re.compile(r'Resolution:\s+(Retina)?.*?([0-9]*)\s+x\s+([0-9]*)')
resReturn = None

resReturn = None
for mtch in resRe.findall(os.popen('system_profiler SPDisplaysDataType').read())
resReturn = f'{mtch[1]} {mtch[2]} {mtch[0]}' if not resReturn or mtch[0] else resReturn
print(resReturn or '640 480')

That gets you the “Retina” line if there is more than one “Resolution” line. If it doesn’t find any “Resolution” lines, it punishes you by assuming a 640x480 display.

Instead of side by side windows, I got overlapping windows, each about 2/3 the width of the display, which is what I got with using the resolution from SPDisplaysDataType.

So, I reverted back to the commented out suggestion, since I don’t use Pathfinder:

tell application "Finder" to set {w, h} to {item 3, item 4} of (bounds of window of desktop as list)
set divisor to 4

Now I get two side by side windows. In total, they span most of the width of the display.

System_profiler returns width and height of 5120 and 2880. The bounds of window method returns width 3968 and height 1318.

It can be vexxing to try to accommodate different systems with a universal script, even one as short as this one.

I’m good with it. I may take out the adaptive lines and just hardcode w and h, since I would prefer narrower windows, anyway.

Thanks again, all.

This is a great tip. Thank you for sharing. I learn a lot just by reading about how others use this amazing software.

1 Like

This is worth the price of admission alone. I did not know this and this is brilliant.

:heart: :slight_smile:

Thanks for the kind words! i’m glad it’s useful to you.

Great script, thanks a lot!
Is there a way to use it with DT3 in full screen mode? Right now it opens one file in a window and the second one in another full screen in the next desktop


Are you on an M1 Mac?

And no, it won’t run in fullscreen.

No, just a normal MacBook Pro and a iMac. Pitt that ist doesn‘t work in Full Screen, Bit Great to know that this script exists!