When I use set dest to choose folder
in the open handler, my droplet will not process all files. It only works wenn I use tell application "System Events" to set dest to choose folder
. What’s the correct way to use choose folder in an enhanced applet? Strange is, that it works in Script Debugger itself or when I have debugging enabled.
that’s my script
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property appletDropName : "Drop your files here" -- text prompt for drop tab
property appletSearchName : "Find your files" -- text prompt for search tab
on open theFiles
set destinationFolder to choose folder with prompt "Select destination folder" with showing package contents without multiple selections allowed
--set destinationFolder to alias "Macintosh HD:Users:Wolfgang:Applications:Vorschau mit Werkzeugleiste.app:Contents:Resources:"
set destinationFolderPosix to POSIX path of destinationFolder
set existingFiles to ""
-- Process Files...
set progress total steps to count of theFiles
set progress completed steps to 0
repeat with aFile in theFiles
tell application "System Events"
set aFilePosix to POSIX path of (aFile as alias) as string
set aFileName to name of (aFile as alias) as string
set aFileDestination to destinationFolderPosix & aFileName
if not (exists (aFileDestination) as POSIX file) then
do shell script "ln -s " & quoted form of aFilePosix & " " & quoted form of aFileDestination
else
set existingFiles to existingFiles & aFilePosix & return
end if
end tell
set progress additional description to "Processing “" & aFileName & "”..."
set progress completed steps to progress completed steps + 1
end repeat
if existingFiles is not "" then
display dialog "Could not create the following symbolic links because objects with the same name exists on the destination folder:" & return & return & existingFiles buttons {"Keep existing objects and ignore this error", "Overwrite existing files, folders or links"} default button 2 cancel button 1 with icon 0 with title name of me
set progress total steps to count of paragraphs of existingFiles
set progress completed steps to 0
repeat with aFilePosix in paragraphs of existingFiles
if aFilePosix as string is not "" then
tell application "System Events"
set aFileName to name of (aFilePosix as string as POSIX file as alias) as string
set aFileDestination to destinationFolderPosix & aFileName
end tell
do shell script "rm " & quoted form of aFileDestination
do shell script "ln -s " & quoted form of aFilePosix & " " & quoted form of aFileDestination
end if
set progress additional description to "Processing “" & aFileName & "”..."
set progress completed steps to progress completed steps + 1
end repeat
end if
end open