As the title suggests. I am having a really hard time getting my script to accept files from a drag-n-drop.
The code is below. I’ve done a bunch of reading, and thought I understood how lists, get selection, and alias / file paths worked… but I am missing something.
Here’s the code as it works today. I select a bunch of files in the finder, then run this script in the editor of from the applescript menu.
The goal: drag files onto an icon, and have it do the same thing.
I’ve tried to replace the “set theList to (get selection)” with a list ( set theList to theList {} ), using ON OPEN statements…
Everytime i change the method of files input, it gives me an error like…
…which, doesn’t seem to exist on google. That said, i thought it meant that the file path can’t be converted properly into what the script needs (alias, string, posix, whatever.)
Any ideas?
tell application "Finder"
display dialog "This app will take the file name and add each word as tags. " & return & return & "As of this release, I will ignore 2 and 4 digit numbers, as the Date-Time is already searchable." with title "Billie's File-to-MacOS-Tag Converter" buttons {"Continue", "Cancel"} default button 1
set theList to (get selection)
set countme to {}
set countme to theList
set selCount to (count of countme)
display dialog "You've selected " & selCount & " files to add tags." with title "Billie's File-to-MacOS-Tag Converter" buttons {"Confirmed", "Cancel"} default button 1
repeat with currentFile in theList
tell currentFile
if label index is 0 then
set currentFiletext to (name of currentFile as text)
set aliasofCurrentFile to (currentFile as alias)
-- Notify of change
-- bredisplay notification "Updating the file " & currentFiletext
-- display dialog currentFiletext
tell me
set taglist to currentFiletext
--fix parens
set taglist to (do shell script "echo \"" & taglist & "\" | tr '(' ' '" as text)
set taglist to (do shell script "echo \"" & taglist & "\" | tr ')' ' '" as text)
-- Fix the double digit numbers in the date
set taglist to (do shell script "echo " & taglist & " | sed 's/[0-9][0-9]*/ /g'" as text)
set taglist to (do shell script "echo " & taglist & " | sed 's/[0-9][0-9][0-9][0-9]*/ /g'" as text)
--do these last to fix the commas and periods
set taglist to (do shell script "echo " & taglist & " | tr . ' '" as text)
set taglist to (do shell script "echo " & taglist & " | tr _ ' '" as text)
set taglist to (do shell script "echo " & taglist & " | tr ' ' ," as text)
-- show me what i'm renaming
end tell
set pathtoFilePosix to "\"" & (the POSIX path of aliasofCurrentFile) & "\""
-- display dialog pathtoFilePosix & return & taglist
do shell script "/usr/local/bin/tag -a " & taglist & " " & pathtoFilePosix
else
set label index to 0
end if
end tell
end repeat
end tell
on tagCmd(f)
do shell script "/usr/local/bin/tag -a " & taglist & " " & quoted form of POSIX path of f -- posix path convert path with colon to use in shell
end tagCmd
Model: Mac Mini Mid 2012, 16GB
AppleScript: Editor 2.10 (194) / AS 2.7
Browser: Safari 537.36
Operating System: Mac OS X (10.13 Developer Beta 3)