Drag-and-Drop with Desktop Files

hh hh at hyperhh.de
Wed Mar 13 19:44:05 EDT 2019

** Get selected files of the file manager (without user interaction like dragDrop) **

(I write the following such that also beginners can read it.)

[a] Solution for MacOS (tested to work on MacOS 10.14):

(a1) Put the following in a field "myScript".

# Full path of selected items in Finder.
tell application "Finder"
   set finderSelList to selection as alias list
end tell

if finderSelList ≠ {} then
   repeat with i in finderSelList
      set contents of i to POSIX path of (contents of i)
   end repeat
   set AppleScript's text item delimiters to linefeed
   finderSelList as text
end if

(a2) Script a button and create a field "OUT".
on mouseUp
   do fld "myScript" as applescript
   put char 2 to -2 of the result into r
   put r into fld "OUT"
end mouseUp

You'll get from the top-layered finder window lines with the full file names.

(a3) Credits.

[b] Solution for Windows (tested to work on Win 7+10):

(b1) Save the following to a file "wscript1.js" in your stacks folder.

var shellWindows = new ActiveXObject("Shell.Application").Windows();
for (var i = 0; i < shellWindows.Count; i++) {
var w = shellWindows.Item(i);
var sel = w.Document.SelectedItems();
for (var j = 0; j < sel.Count; j++) {
var item = sel.Item(j);

(b2) Script a button and create a field "OUT".

on mouseUp
  put the effective filename of this stack into p
  set itemdel to slash
  put "wscript1.js" into last item of p
  put shell("wscript "&p) into fld "OUT"
end mouseUp

You'll get for each explorer window its name and, for each selected file in that,
the short file name followed in the next line by the long file name.

(b3) Credits.

[c] Solution for linux:

Linux nerds of the use-list, please complete here (at least for ubuntu 1604) ...

More information about the use-livecode mailing list