My new favorite way to write (this week)

Ah, that’s cool. Not sure why it’s not working here. A nice mystery to work on this evening.

It is not working on my computer as well. Keep us informed if you find a solution.

If it’s not working for you it’s probably helpful to mention the version numbers of your macOS and DT—just in case that makes a difference. I’m using DT 3.7.2 on macOS 11.5.1.

How I use the script:

  • select two files in DT;
  • click on the DT script icon in the menu bar and go to Edit > Open in two windows (see note below as to name of the script);
  • click on the script Open in two windows.

Note: I appear to have three versions of the script (Open in two windows DT3, Open in two windows_DT3, and Open in two windows.) However all work for me.


I’m running MacOS Big Sur 11.5.1 on a late 2015 iMac. Devonthink is Devonthink Server Edition 3.7.2.

I’ve fiddled with a few options like double-click to open externally, which is what I like, but the script is not doing anything.

The log window remains empty.

It’s going to be a busy weekend. When I can get some troubleshooting time in, I’ll post results.

I wish I were a native speaker in Applescript, but I can work through it.

As a final suggestion, try rebooting!


Let me double-check on my Big Sur machines.

Window width is calculating strangely on Big Sur on my M1 Air.
Works as expected on my Intel Mini.

I’ll have to look at that for M1 Macs.

Bonus Feature!

If you weren’t aware of it @Stephen_C, et al: This script can open the same file in two separate windows, if desired.
This was actually the original intent when I wrote it.

Back in the days, before @cgrunenberg implemented side-by-side in DEVONthink 3, it was an ad-hoc way to edit the source of a Markdown file, save it, and see the rendered change in the same file in the second window. Kind of a poor man’s Marked.

Bonus Feature #2!

If you select a single file and that file has an associated annotation file, they should both open up in side-by-side windows. Perhaps less necessary with the Annotation inspector but stil perhaps useful.


Thanks @Stephen_C and @BLUEFROG

I have DT 3.7.2, MacOs 11.4, Mac Intel.

I deleted all “two windows” scripts and installed them again. Now, it is working. However, I do not get the two files that I selected in two windows side-by-side.

Can you share with us the outcome of this script on the screen?

You’re welcome :slight_smile:
This is on an Intel Macbook on Catalina…

Note: The current version of macOS Big Sur is 11.5.1. We suggest you stay current with operating system point releases.

This line is where things are running off the rails:

set xWidth to (w / divisor) as integer

The problem starts earlier, in this line:

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

sed isn’t getting just the [0-9]* x [0-9]* part.

Here’s my change:

– set displayRes to (do shell script “system_profiler SPDisplaysDataType | grep Resolution | head -n 1 | sed -E 's_.* ([0-9]) x ([0-9])\1 \2’”)
– set {w, h} to {word 1, word 2} of displayRes

set displayRes to (do shell script “system_profiler SPDisplaysDataType | grep Resolution”)

set {w, h} to {word 4, word 6} of displayRes

I was in the middle of fixing the sed when my wife started yelling about lunch. Er, sweetly suggesting it was time to eat, that is.

The script runs now, but the widths of the new windows are wider than intended.

Also, I have two displays on my system.

Gotta dash…

1 Like

Thanks.very useful.

1 Like

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.