How can I create a macro to adjust the clicking position based on the fullscreen status?

I am trying to create a macro to copy text from an open document and search in DevonThink. The position of the input box in DevonThink varies depending on the fullscreen status of the app. It is higher while in fullscreen compared to when not in fullscreen.
Can a macro be adjusted to take into account the fullscreen status of the app and adjust the clicking point accordingly?

Hey Mirizzi,

Copy what text? All text? Some of the text?

Why are you clicking?


I am trying to copy the highlighted text in the front document, and search for the text in DevonThink.
Because I do this several times every hour, I am trying to automate the copying in the front document, switching to DevonThink, and pasting the copied text into the search field of DevonThink.

Why not:

⌘c :: copy
Make DT active
⌥⌘f :: make search field active
⌘p :: paste


1 Like

You may be able copy the selected text directly to the DT search field using a KM Execute script action which is some variant of this.

(ver 0.3 updated, taking a cue from Chris Stone's AS version below, to allow for variation in DEVONthink toolbar setup. Chris's version should work on pre as well as post Yosemite versions of OSX, whereas this uses JavaScript for Applications, and needs Yosemite onwards)

Copy selected text to DEVONthink search field.kmmacros (19.6 KB)

// ver 0.3 adjusted in case of variation in number of DT toolbar groups
(function () {
  var a = Application.currentApplication(),
    strClip = (a.includeStandardAdditions = true, a).theClipboard({
      as: "text"
    fldSearch = function () {
      return (strClip ? function () {
        var se = Application("System Events"),
          lstApps = se.applicationProcesses.where({
            name: "DEVONthink Pro"
          lstWins = (procDT = lstApps.length ? lstApps[0] : null) ?
            subrole: "AXStandardWindow"
          }) : null;
        return lstWins.length ? lstWins[0] : [];
      }() : []).reduce(function (a, x) {
        if (null === a) {
          var c = x.textFields.where({
            description: "search text field"
          return c.length ? c[0] : null;
        return a;
      }, null);
  if (strClip && fldSearch) {
    return procDT.visible() || (procDT.visible = true),
      procDT.frontmost = true,
      fldSearch.value = strClip, fldSearch.value();

Ha! Rob beat me to the punch by an hour.   :smile:

Here’s my variant which is tolerant of toolbar variations:

# Auth: Christopher Stone <>
# dCre: 2015/10/10 12:45
# dMod: 2015/10/10 13:11
# Appl: System Events & DEVONthink Pro (or pro office).
# Task: Set the Value of the Search-Field in DEVONthink Pro (or pro office) to the clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @DEVONthink_Pro, @Set, @Search, @Field

tell application "System Events"
  tell application process "DEVONthink Pro Office"
    if its visible = false then set its visible to true
    set frontmost to true
    tell (first window whose subrole is "AXStandardWindow")
      tell toolbar 1
        tell groups
          repeat with i in text fields
            if i's description is "search text field" then
              set value of (get contents of i) to (get the clipboard)
              exit repeat
            end if
          end repeat
        end tell
      end tell
    end tell
  end tell
end tell

So the macro would:

  • Copy the selected text.
  • Delay 0.05 or so.
  • Run the AppleScript.


1 Like

Thanks a million. This works perfectly except when Devonthink is in fullscreen mode. Also, I had to change the process name to “DEVONthink” because I have the personal edition.

Thanks a million. The script brings Devonthink to the front but does not change the contents of the search box. Do I have to modify anything other than the process name?

You are right - the AXWindows list for the app seems to be empty in full and split screen modes on 10.11

Not sure whether that means it is entirely out of “System Events” scripting range …

It does change the contents of the find-field here on my system with DTProOffice.

# Tested with DT-Personal on my 10.11 system.
# Full-Screen is NOT supported.
set findStr to "devon"

tell application "System Events"
  tell application process "DEVONthink"
    set frontmost to true
    # delay 2
    tell (first window whose subrole is "AXStandardWindow")
      tell text field 1 of group 3 of toolbar 1
        set focused to true
        set value to findStr
      end tell
    end tell
  end tell
end tell

If this still doesn't work try uncommenting the delay line.

Apparently System Events only sees the menu bar when DEVONthink is in full-screen mode.

This would seem to be a very big oversight.

DEVONthink Personal has no native scriptability.

But even DTProOffice cannot script the find field directly.

There is a scripted find, but it returns a list of found items to AppleScript and does not affect the UI.

Considering how scriptable DTPO is, I think this is pretty silly.


Keywords: applescript, devonthink

Hey Mirizzi,

The only way I can see to get a click working in full-screen mode is to use a Click On Image action to find the {Info} button next to the search field and then offset the click to the field.

It seems more sensible to use Kirby's suggestion, although I'd use a Menu action rather than a keystroke.

* Tested in full-screen mode on OSX 10.11.


Got it working using Kirby’s suggestion with your suggested Menu action. Thanks.