I would like to use the KM Action “Move and Click and Drag” to select text in Safari. This works as expected in other programs (e.g.: Preview, Skitch, &c.): the action performed by the KM macro exactly mimics the same action performed by a user. But in Safari, when I click, drag, and release, I select the text over which I dragged. The KM Action, in Safari, moves the mouse cursor, but does not select the text over which the cursor has been programmed to move.
Am I doing something wrong? Are my expectations wrong? Is there an easy fix? Is there a work-around?
Hi Tunes. There is no “solution”. In every application I tried except Safari, the KM Action “Move and Click and Drag” exactly mimics the same action when done by the user. The universal action of clicking-and-dragging is to select. This works as expected in Preview. What is selected will depend on the type of document in the active window.
I tried your suggestion two ways:
— adding an Action to make Safari active prior to the click-and-drag Action, and
— using AppleScript.
Neither had any effect, afaict. The Action is being executed — I can see the mouse cursor move to the specified start position and then jump the specified number of pixels — but nothing is being selected in the Safari window.
I reported this as possibly a bug. Peter replied that it was a Safari issue, and suggested finding a work-around.
In trouble-shooting, I noticed that if I execute the Action “Click … Drag” twice, on the second time the items under the click-and-drag area are selected. (The first Action seems to make the second work — they don’t have to be identical.)
So my work-around, which seems robust at this point, is to simply put the Action “Click … Drag” in twice, and copy to the Clipboard after the second one.
If you or anyone can suggest further trouble-shooting methods, I will try to look into this further. I am curious why the action done by the user with a trackpad (in my case) are not initially identical to the mouse-down, etc., actions executed by KM.
Hi Chris — these were helpful — thank you for them. I now have something that works for my current need reliably.
What I don’t understand and would like to understand is this: how is it that the user’s mouse cursor actionalways works as expected (it selects what is under the dragged-over area), but the KM action click-and-drag only sometimes works in Safari? I could understand the macro not doing what I expect when the user action doesn’t do what I expect; I can’t figure out how Safari can treat my use of the mouse cursor differently than the inputs provided by the KM mouse cursor Actions.
Peter can perhaps give an idea of how the nuts and bolts of this work.
But Keyboard Maestro is NOT the user. KM artificially emulates user actions.
Furthermore Peter has used only publicly available APIs in Keyboard Maestro, so he doesn’t have to reengineer everything every time Apple makes a simple change — and not hacking into the system does limit KM in some ways.
Safari is evidently doing something a little different with it’s text display than some other apps, and that is not necessarily documented anywhere — especially in the context of driving the UI with an automation utility.
Especially when the structure you’re working with is known.