/ Published in: AppleScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(* This always gets a path to a folder *) tell application "Finder" try -- Try to get the current item(s) selected in Finder first set mySel to selection if (count of mySel) < 1 then -- If there's no selection try to get the path of the window instead -- Otherwise just return the desktop since the user could have used the context menu from there if (count of windows) > 0 then set myFolder to target of first window else set myFolder to desktop end if else set myFolder to first item of mySel end if if (count of mySel) > 1 then display dialog "Multiple items selected, only getting first item of " & quoted form of (displayed name of myFolder as text) with icon end if -- If the selection is a file or an alias to a file we get the containing folder instead if class of myFolder is document file or (class of myFolder is alias file and file type of myFolder is missing value) then set myFolder to container of myFolder end if -- Do whatever you want with the folder here... on error errMsg beep display dialog errMsg return end try end tell