Hey there! Thanks for your help! I'm trying to use an AppleScript in KM, but I can't get it to work, I need to set ChosenFolder to /Users/x/Downloads/_Zoli QC Completed/Here, what am I doing wrong? It was originally set chosenFolder to (choose Folder) and that would launch a pop up window to select a directory but I don't want this step as I'll open always the same folder
set chosenFolder to (POSIX path /Users/x/Downloads/_Zoli QC Completed/Here)
tell application "Finder" to set fileList to files of chosenFolder
set TID to text item delimiters
set text item delimiters to space
repeat with aFile in fileList
set fileName to name of aFile
set textItems to text items of fileName
if (count textItems) = 1 then
set fileExtension to name extension of aFile
set folderName to text 1 thru ((get offset of "." & fileExtension in fileName) - 1) of fileName
else
set folderName to first item of textItems
end if
set sourceFile to quoted form of POSIX path of (aFile as text)
set destinationFile to quoted form of (POSIX path of chosenFolder & folderName & "/" & fileName)
do shell script "ditto " & sourceFile & space & destinationFile
do shell script "rm " & sourceFile
end repeat
set text item delimiters to TID
The argument of POSIX path should be a string, and you haven't wrapped it in double quotes, so it's just a sequence of 3 space-delimited tokens of uncertain meaning.
I found this script that will create folders based on filenames, but the first line opens up a pop up window to ask me to choose the folder where it will find the files. Because I'm doing a big macro, I'm trying to get rid of this pop up window and to set the ChosenFolder directly to /Users/x/Downloads/_Zoli QC Completed/Here)
Original Script:
set chosenFolder to (choose folder)
tell application "Finder" to set fileList to files of chosenFolder
set TID to text item delimiters
set text item delimiters to space
repeat with aFile in fileList
set fileName to name of aFile
set textItems to text items of fileName
if (count textItems) = 1 then
set fileExtension to name extension of aFile
set folderName to text 1 thru ((get offset of "." & fileExtension in fileName) - 1) of fileName
else
set folderName to first item of textItems
end if
set sourceFile to quoted form of POSIX path of (aFile as text)
set destinationFile to quoted form of (POSIX path of chosenFolder & folderName & "/" & fileName)
do shell script "ditto " & sourceFile & space & destinationFile
do shell script "rm " & sourceFile
end repeat
set text item delimiters to TID
You'll find this easier to do -- and, importantly, to maintain -- using KM actions rather than AppleScript. For starters, look at the "Split Path" action and how you can use it to get the name, minus extension, of a file so you can use it to create a folder.