I was wondering how the script may do its duty if you move end tell before the repeat statement.
So I tested.
set kDirectoryToArchive to contents of (choose folder without invisibles)
tell application "Finder"
set subFolders to (every folder of kDirectoryToArchive) as list
end tell -- Finder
repeat with eachFolder in subFolders
set a to eachFolder as alias
set b to POSIX path of a
set kName to (name of eachFolder) as string
log kName
set defDel to AppleScript's text item delimiters
if kName contains " " then
set AppleScript's text item delimiters to " "
set newname to text items of kName
set AppleScript's text item delimiters to "_"
set thisItem to (newname as string)
set AppleScript's text item delimiters to defDel
else
set thisItem to kName
end if
set a to "tar -jcvf /Volumes/XX/" & thisItem & ".tar.bz2 " & quoted form of b
log a
# do shell script a
end repeat
display dialog "All donez. kthxbye :)"
The log report is :
tell application “AppleScript Editor”
choose folder without invisibles
→ alias “Macintosh HD:Users:yvankoenig:Documents:tempo:”
end tell
tell application “Finder”
get every folder of alias “Macintosh HD:Users:yvankoenig:Documents:tempo:”
→ {folder " ebay" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk, folder " pour Essais" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk, folder “2011-06-06” of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk}
get folder " ebay" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ alias “Macintosh HD:Users:yvankoenig:Documents:tempo: ebay:”
get name of folder " ebay" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ " ebay"
end tell
(* ebay*)
(tar -jcvf /Volumes/XX/_ebay.tar.bz2 ‘/Users/yvankoenig/Documents/tempo/ ebay/’)
tell application “Finder”
get folder " pour Essais" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ alias “Macintosh HD:Users:yvankoenig:Documents:tempo: pour Essais:”
get name of folder " pour Essais" of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ " pour Essais"
end tell
(* pour Essais*)
(tar -jcvf /Volumes/XX/_pour_Essais.tar.bz2 ‘/Users/yvankoenig/Documents/tempo/ pour Essais/’)
tell application “Finder”
get folder “2011-06-06” of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ alias “Macintosh HD:Users:yvankoenig:Documents:tempo:2011-06-06:”
get name of folder “2011-06-06” of folder “tempo” of folder “Documents” of folder “yvankoenig” of folder “Users” of startup disk
→ “2011-06-06”
end tell
(2011-06-06)
(tar -jcvf /Volumes/XX/2011-06-06.tar.bz2 ‘/Users/yvankoenig/Documents/tempo/2011-06-06/’)
tell application “AppleScript Editor”
display dialog “All donez. kthxbye :)”
No, you aren’t drunk.
The script is supposed to issue an end tell statement but it continue to speak to the folder for the three instructions :
set a to eachFolder as alias
set b to POSIX path of a
set kName to (name of eachFolder) as string
This surprising behavior is specific to the Finder.
As I don’t like this application, I tried to do the trick with System Events but this one is more coherent.
set kDirectoryToArchive to contents of (choose folder without invisibles)
tell application "System Events"
set subFolders to (path of every folder of disk item (kDirectoryToArchive as text)) as list
end tell -- System Events
repeat with eachFolder in subFolders
set a to eachFolder as text
set b to POSIX path of a
set kName to (name of disk item eachFolder) as string # DON'T COMPILE !!
log kName
set defDel to AppleScript's text item delimiters
if kName contains " " then
set AppleScript's text item delimiters to " "
set newname to text items of kName
set AppleScript's text item delimiters to "_"
set thisItem to (newname as string)
set AppleScript's text item delimiters to defDel
else
set thisItem to kName
end if
set a to "tar -jcvf /Volumes/XX/" & thisItem & ".tar.bz2 " & quoted form of b
log a
--do shell script a
end repeat
display dialog "All donez. kthxbye :)"
To be able to compile I edited it as :
set kDirectoryToArchive to contents of (choose folder without invisibles)
tell application "System Events"
set subFolders to (path of every folder of disk item (kDirectoryToArchive as text)) as list
end tell -- System Events
repeat with eachFolder in subFolders
set a to eachFolder as text
set b to POSIX path of a
tell application "System Events" to set kName to (name of disk item eachFolder) as string
log kName
set defDel to AppleScript's text item delimiters
if kName contains " " then
set AppleScript's text item delimiters to " "
set newname to text items of kName
set AppleScript's text item delimiters to "_"
set thisItem to (newname as string)
set AppleScript's text item delimiters to defDel
else
set thisItem to kName
end if
set a to "tar -jcvf /Volumes/XX/" & thisItem & ".tar.bz2 " & quoted form of b
log a
--tell me to do shell script a
end repeat
display dialog "All donez. kthxbye :)"
But, my own choice would be :
set kDirectoryToArchive to contents of (choose folder without invisibles)
tell application "System Events"
set subFolders to (path of every folder of disk item (kDirectoryToArchive as text)) as list
repeat with eachFolder in subFolders
set kName to (name of disk item eachFolder) as string
log kName
my archiveAfolder(eachFolder, kName)
end repeat
end tell
display dialog "All donez. kthxbye :)"
on archiveAfolder(a_Folder, k_Name)
if k_Name contains " " then
set defDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set newname to text items of k_Name
set AppleScript's text item delimiters to "_"
set thisItem to (newname as string)
set AppleScript's text item delimiters to defDel
else
set thisItem to k_Name
end if
quoted form of POSIX path of a_Folder
set a to "tar -jcvf /Volumes/XX/" & thisItem & ".tar.bz2 " & result
log a
do shell script a
end archiveAfolder
Yvan KOENIG (VALLAURIS, France) dimanche 9 septembre 2012 21:48:50