Re: drag and drop with cliclick
Re: drag and drop with cliclick
- Subject: Re: drag and drop with cliclick
- From: David Gregg <email@hidden>
- Date: Mon, 07 Aug 2017 07:14:43 -0600
Hi Yvan,
Here is what I use for a mouse drag and drop with CLIClick:
my dragAndDropMouse(0, 23, 100, 100, 200)
on dragAndDropMouse(startPointX, startPointY, endPointX, endPointY, delayTime)
set scriptContent to "usr/local/bin/cliclick dd:" & startPointX & "," &
startPointY & space & "w:" & delayTime & space & "du:" & endPointX & "," &
endPointY & space & "w:" & delayTime
do shell script scriptContent
end dragAndDropMouse
You need to use the "dd" for "drag and drop start" and "du" for "drag and drop
end". In some cases it might also require a wait or delay to work properly. It
will give you an error with a wait of 0 so modify as you see fit.
David Gregg
> On Aug 7, 2017, at 6:28 AM, Yvan KOENIG <email@hidden> wrote:
>
> Hi all.
>
> I'm trying to help a user which must work under 10.10.
> Alas, with this system there is an annoying problem to drive Notes with
> AppleScript.
> When we try to save an attachment in a note, the file storing the attached
> item is created but is erased when we quit the application.
> The save command doesn't do what it's supposed to achieve.
> Trying to build a workaround, I wrote a piece of code supposed to mimic a
> drag and drop of the selected icon onto the body area of the newly created
> note.
> At this time, the script achieve quite all the job minus the drag and drop
> action.
> I assumes that I misunderstood something in the manual of "cliclick 3.3,
> 11/12/2016"
>
> Here is the complete script which may be used under 10.10 and higher.
>
> property remind_list : "- Import"
>
> set sys2 to (item 2 of my decoupe(system version of (system info), ".")) as
> integer
> if sys2 < 11 then
> set myAccount to "On my Mac" # Edit to fit your needs
> else
> set myAccount to "Sur mon Mac" # Edit to fit your needs
> end if
> set pathToCliclick to "/Users/admin/bin/cliclick " # Edit to fit your needs
>
> tell application "Finder" # Supposed to point an icon in icon view.
> set thepict to (selection) as alias
> set {Xs, Ys} to desktop position of thepict # Coordinale of the center
> of the selected icon
> end tell
>
> tell application "Notes"
> #prepare default import list
> set all_lists to name of every folder
> log all_lists
> if remind_list is not in all_lists then
> log "the folder doesn't exist"
> log (get name of every account)
> tell account myAccount # REQUIRED
> make new folder with properties {name:remind_list}
> end tell # REQUIRED
> log (get name of every folder)
> end if
> set shdt to text 2 thru -1 of POSIX path of (time string of (current
> date))
> set new_pict_import to "Bildimport-" & shdt
> --set new_pict_import to "Tagada"
> try
>
> #build reminders
> set new_note to make new note at folder remind_list with
> properties {name:new_pict_import}
> # The instruction below create an attachment under 10.11 or
> higher
> if sys2 > 10 then make new attachment at end of attachments of
> new_note with data file (thepict as text)
>
> # Alas, the instruction below doesn't do its job under 10.10 so
> the created attachment doesn't appear on screen and is dropped when we close
> the app.
> save
>
> # Will try to drag and drop the selected icon onto the body of
> the note
> if sys2 < 10 then
> error "Requires at least 10.10"
> else if sys2 = 10 then
> tell application "System Events" to tell process "Notes"
> set frontmost to true
> delay 0.5
> -- name of windows --> {"Notes"}
> tell window 1 # no title under 10.10, "Notes"
> -- class of UI elements --> {splitter
> group, button, button, button, static text} (10.10)
> tell splitter group 1
> -- class of UI elements -->
> {scroll area, splitter, group, splitter, group} (10.10)
> tell scroll area 1
> -- class of UI elements
> --> {outline}
> tell outline 1
> -- class of UI
> elements --> {row, row, row, row, column}
> -- class of UI
> elements of UI element 1 of rows --> {{static text}, {static text}, {static
> text}, {text field}}
> -- value of
> static text 1 of UI element 1 of rows 1 thru -2 --> {"On My Mac", "Tous On My
> Mac", "Notes"} (10.10)
> -- value of
> text field 1 of UI element 1 of row -1 --> "- Import"
> set {Xf, Yf} to
> position of text field 1 of UI element 1 of row -1 -- coordinale of a point
> in the target folderName
> tell me to do
> shell script pathToCliclick & "c:" & Xf & "," & Yf
> end tell -- outline 1
> end tell -- scroll area 1
>
> -- class of UI elements -->
> {group, splitter, group}
> tell group 1
> -- class of UI elements
> --> {scroll area}
> -- class of UI elements
> of scroll area 1 --> {table}
> -- class of UI elements
> of table 1 of scroll area 1 --> { row, column}
> -- class of UI elements
> of row 1 of table 1 of scroll area 1 --> {UI element}
> -- class of UI elements
> of UI element 1 of row 1 of table 1 of scroll area 1 --> {static text, static
> text} (10.10)
> repeat with i from 1 to
> count rows of table 1 of scroll area 1
> if value of
> static text 1 of UI element 1 of row i of table 1 of scroll area 1 =
> new_pict_import then
> -->
> {"Bildimport-21/46/24", "Tagada"}
> tell
> static text 1 of UI element 1 of row i of table 1 of scroll area 1
>
> set {x, y} to its position
>
> set {w, h} to its size
>
> set {Xt, Yt} to {x + (w div 2), y + (h div 2)} # coordinate of a point in the
> title of the new note
>
> tell me to do shell script pathToCliclick & "c:" & Xt & "," & Yt
> end tell
> exit
> repeat
> end if
> end repeat
> end tell -- group 1
> tell group 2
> -- class of UI elements
> --> {scroll area, group, group, static text}
> -- name of static text
> 1 --> "6 août 2017 à 21:46"
> -- class of UI elements
> of UI element 1 --> {UI element} (10.10)
> -- class of UI elements
> of UI element 1 of UI element 1 --> {group, group} (10.10)
> tell UI element 1 #
> (10.10)
> set {x, y} to
> its position
> set {w, h} to
> its size
> set {xd, yd} to
> {x + (w div 2), y + (h div 2)} # coordinate of a point in the body area of
> the new note
> end tell
> end tell -- group 2
> end tell -- splitter group 1
> end tell -- window "Notes"
> end tell -- System Events …
>
> tell me to do shell script pathToCliclick & "dd:" & Xs
> & "," & Ys & " m:" & xd & "," & yd & " du:" & xd & "," & yd # What's wrong ?
> else
> # Here, macOS 10.11 or higher
> tell application "System Events" to tell process "Notes"
> set frontmost to true
> --name of windows --> {"Notes"}
> tell window "Notes"
> --class of UI elements --> myAccount
> tell splitter group 1
> --class of UI elements -->
> {button, scroll area, splitter, splitter group}
> tell scroll area 1
> --class of UI elements
> --> {outline}
> tell outline 1
> --class of UI
> elements --> {row, row, row, row, column}
> --class of UI
> elements of UI element 1 of rows --> {{static text}, {static text}, {static
> text}, {text field}}
> --value of
> static text 1 of UI element 1 of rows 1 thru -2 --> {"Sur mon Mac", "sur mon
> Mac (tout)", "Notes"}
> --value of text
> field 1 of UI element 1 of row -1 --> "- Import"
> set {Xf, Yf} to
> position of text field 1 of UI element 1 of row -1 -- coordinale of a point
> in the target folderName
> tell me to do
> shell script pathToCliclick & "c:" & Xf & "," & Yf
> end tell -- outline 1
> end tell -- scroll area 1
>
> tell splitter group 1
> --class of UI elements
> --> {group, splitter, group}
> tell group 1
> --class of UI
> elements --> {scroll area}
> --class of UI
> elements of scroll area 1 --> {table}
> --class of UI
> elements of table 1 of scroll area 1 --> {row, row, column}
> --class of UI
> elements of row 1 of table 1 of scroll area 1 --> {UI element}
> --class of UI
> elements of UI element 1 of row 1 of table 1 of scroll area 1 --> {image,
> image, static text, static text, static text}
> repeat with i
> from 1 to count rows of table 1 of scroll area 1
> if
> value of static text 1 of UI element 1 of row i of table 1 of scroll area 1 =
> new_pict_import then
>
> --> {"Bildimport-21/46/24", "Tagada"}
>
> tell static text 1 of UI element 1 of row i of table 1 of scroll area 1
>
> set {x, y} to its position
>
> set {w, h} to its size
>
> set {Xt, Yt} to {x + (w div 2), y + (h div 2)} # coordinate of a
> point in the title of the new note
>
> tell me to do shell script pathToCliclick & "c:" & Xt & "," & Yt
>
> end tell
>
> exit repeat
> end if
> end repeat
> end tell -- group 1
>
> tell group 2
> --class of UI
> elements --> {static text, scroll area}
> tell scroll
> area 1
> set {x,
> y} to its position
> set {w,
> h} to its size
> set
> {xd, yd} to {x + (w div 2), y + (h div 2)} # coordinate of a point in the
> body area of the new note
> end tell
> end tell -- group 2
> end tell -- splitter group 1
> end tell -- splitter group 1
> end tell -- window "Notes"
> end tell -- System Events …
>
> tell me to do shell script pathToCliclick & "dd:" & Xs
> & "," & Ys & " m:" & xd & "," & yd & " du:" & xd & "," & yd # What's wrong ?
> end if
>
> on error err
> activate
> display dialog err
> end try
>
> end tell # Notes
>
> #=====
>
> on decoupe(t, d)
> local oTIDs, l
> set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text
> item delimiters, d}
> set l to text items of t
> set AppleScript's text item delimiters to oTIDs
> return l
> end decoupe
>
> #=====
>
> I hope that some of you will be able to give the correct incantation.
>
> Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) lundi 7 août
> 2017 14:27:28
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden