Positioning DEVONthink Pro window

I am reluctant to post these two very simple scripts which are the first I have written, but both Korm and BLUEFROG have encouraged me to do so.

Script 1 will move the DEVONthink Pro window to a predetermined position on the desktop which is some distance in from the left-hand side.
Script 2 will return the window to aligne with the left-hand edge of the desktop. Save with appropriate titles.

Script 1.
Script 1.jpg

Script 2.
Script 2.jpg

Hope at least one person will find them useful. Any advice concerning them and how to improve them would be welcome.

Thanks!

Bravo, Allsop! :smiley:

It’s a nice tidy little bit of code. If you’re happy with it, that’s what counts.

It reminds me of some window division scripting I did. If I had n windows, how could I evenly distribute them on my screen? How about allowing for the dock and the toolbar of each window?

Or how about a repeat loop that drifts your window across the screen?

Random size and position of the window (always fun for a gentle prank)?

Or maybe simply having the script toggle between two states instead of running two scripts?

Fun stuff! 8)

PS: Here’s the world’s smallest Applescript…


beep

```  <img src="//devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/1X/442e459c5ced45cb70e8a05e77e07cea6fee4928.gif" width="15" height="17" alt=":mrgreen:" title="Mr. Green"/>

Hi Allsop, Instead of inserting a picture of your code, just click the ‘Code’ button in the editing window. That will insert start and end tags into your message where you can paste the code so that others can copy it. Like so:


tell application "Finder" to set the bounds of the window of application "DEVONthink Pro" to {156, 25, 1351, 865}


tell application "Finder" to set the bounds of the window of application "DEVONthink Pro" to {9, 22, 1204, 862}

Thanks for your kind comments BLUEFROG, I appreciate the encouragement :slight_smile: As for repeat loops, random sizes, positioning, and toggling…huh? I use these scripts frequently to get to a pasteboard application than open on the side of my screen so I need DTPO out of the way & then to return it to the side when used the pasteboard app so would toggling enable me to do this? If so hints on how to write it into my code would be much appreciated as I haven’t got to toggling yet!!! Cheers.

Thanks clane47 for your coment and advice :slight_smile: Korm has also privately mailed me on this! Cheers.

Following advice reposting codes inline.

Script 1 will move the DEVONthink Pro window to a predetermined position on the desktop which is some distance in from the left-hand side.


tell application "Finder" to set the bounds of the window of application "DEVONthink Pro" to {156, 25, 1351, 865}

Script 2 will return the window to aligne with the left-hand edge of the desktop. Save with appropriate titles.


tell application "Finder" to set the bounds of the window of application "DEVONthink Pro" to {9, 22, 1204, 862}

Here are a couple alternatives to consider

The first, tells the System Events controller, which is one of the underlying OS X processes that controls the interface. Finder is passing on the directive to System Events, and so addressing System Events directly is closer to the action. I also suggest specifying which window to resize - in this case, the first (frontmost) window:


tell application "System Events" to set the bounds of the first window of application "DEVONthink Pro" to {156, 25, 1351, 865}

The second, tells DEVONthink itself to set the window bounds. System Events will tell DEVONthink to do the work, so this variation of the script goes directly to the controlling application. I’ve also used DEVONthink’s private terminology for windows, in this case think window 1 – which is also the frontmost window. The final change here is to use the application’s ID as it is known to OS X. In some cases, the ID can avoid confusion (as for instance a recent scripting bug that causes Evernote to forget who it is). There is an even more technical variety of ID, but we’ll save that for the post-doctoral meet-up :confused:

tell application id "com.devon-technologies.thinkpro2" to set the bounds of think window 1 to {156, 25, 1351, 865}

It’s helpful to know that there is usually more than one approach to coding – some techniques might be more “precise” (a fuzzy concept in coding, as it turns out) than others.

korm brings up excellent points. Some applications have higher levels of control of some functions. Finder and System Events (which have overlapping functions in some aspects) can control window positions.

I think it’s always preferable to talk to the focused application whenever possible but some applications may not have some functions in their vocabulary. That’s when System Events may do what you need.

Here’s a silly example with a repeat loop. See if it makes sense to you…

tell application id "com.devon-technologies.thinkpro2"
	activate -- Brings DEVONthink to front
	repeat with a from 0 to 100 by 10
		set bounds of window 1 to {a, 100, a + 500, 600}
		delay 0.2 -- Pauses slightly so you can see the window move.
	end repeat
end tell

Thanks korm & BLUEFROG. I shall “play” with these and try to learn from them…much obliged 8)

Thanks to all the advice here, for which I am really very grateful, I have combined my two scripts and refined them…I think :wink: Now the whole operation is much slicker and having only one script cuts the work in half. The only trouble I now have is that the script works fine from the menu bar but it will not work through Launchbar as the original two scripts did. I can live with that but it would be good to get it working through LB. I have the folder indexed and the other scripts I have work well through LB, so I think it must be something to do with the dialogue as that seems to simply not appear when using LB. Any advice most welcome. Cheers.

Meant to post the code :blush: ```
tell application id “com.devon-technologies.thinkpro2” to set the bounds of think window 1 to {156, 25, 1351, 865}
display dialog “Return to edge?”
tell application id “com.devon-technologies.thinkpro2” to set the bounds of think window 1 to {9, 22, 1204, 862}

(Removed – pointless and did not address what the reader was looking for.)

(Removed – off topic blather.)

Thanks korm for this. I tried the script both from the Menu and using LaunchBar with success in both cases, so that is indeed an alternative that works well. The good thing about my version, however, is that the dialog screen remains on the screen until I want to return the window to the edge. The scenario is that I have a pasteboard app which is hidden in the left side of the screen until I move the mouse to that edge of the screen whereupon it slides out for me to access it, (this little app holds clipping) but because I typically have DTPO and my genealogical aplication open at the same time I need to slide DTPO over to the right to see the open pasteboard; so I run the script, DTPO slides over with the dialog still showing and I can access the pasteboard, do what I want and then click on okay in the dialog and hey presto mission accomplished. In other words I do not have to run the script twice which I do with your new version.

Thanks also for ypur last post which I found very useful and have downloaded Dialog Maker. Regards.

I use a nice little app called “window magician”

You have to tell it what to do for each window in any given application.

With Cyber Monday coming up soon perhaps it will be on sale?

I think it’s by Koingo