两天前我学到了一些关于applescripting的知识 - 这是我第一次“编程”,所以你可能会看到一些有趣的东西:
tell application "Finder"
--I don't really know why I use as string but otherwise it won't work
set strFilepath to selection as string
set mainFolder to strFilepath
if (exists strFilepath & "ro") is false then
make new folder at mainFolder with properties {name:"ro"}
make new folder at mainFolder & "ro" with properties {name:"carta"}
make new folder at mainFolder & "ro" with properties {name:"A4"}
end if
if (exists strFilepath & "ingl") is false then
make new folder at mainFolder with properties {name:"ingl"}
make new folder at mainFolder & "ingl" with properties {name:"carta"}
make new folder at mainFolder & "ingl" with properties {name:"A4"}
end if
if (exists strFilepath & "es") is false then
make new folder at mainFolder with properties {name:"es"}
make new folder at mainFolder & "es" with properties {name:"carta"}
make new folder at mainFolder & "es" with properties {name:"A4"}
end if
if (exists strFilepath & "it") is false then
make new folder at mainFolder with properties {name:"it"}
make new folder at mainFolder & "it" with properties {name:"carta"}
make new folder at mainFolder & "it" with properties {name:"A4"}
end if
if (exists strFilepath & "fr") is false then
make new folder at mainFolder with properties {name:"fr"}
make new folder at mainFolder & "fr" with properties {name:"carta"}
make new folder at mainFolder & "fr" with properties {name:"A4"}
end if
if (exists strFilepath & "port") is false then
make new folder at mainFolder with properties {name:"port"}
make new folder at mainFolder & "port" with properties {name:"carta"}
make new folder at mainFolder & "port" with properties {name:"A4"}
end if
--it does what I want up until here
set allFiles to entire contents of mainFolder
--here I get an error nummber -1728, I guess because of that string...
try
--I guess this code also doesn't work… I have PDF files that end like xxx_it_carta.pdf, xxx_it_A4.pdf, xxx_en_carta.pdf, etc
search of (name of every item of allFiles) for "_it_carta"
if file exists then move to mainFolder & "it" & "carta"
end try
search of (name of every item of allFiles) for "_it_A4"
try
if file exists then move to mainFolder & "it" & "A4"
end try
--and so on
end tell
请帮我安排这段代码,这样我就可以开始工作了,我会更加了解Applecript。
谢谢!
答案 0 :(得分:0)
您可以尝试以下内容:
set folderNameList to {"ro", "ingl", "es", "it", "fr", "port"}
tell application "Finder"
set strFilepath to (get selection) as text
repeat with folderName in folderNameList
if not (exists folder (strFilepath & folderName)) then make new folder at strFilepath with properties {name:folderName}
end repeat
set allFiles to entire contents of folder strFilepath
-- not clear on your move command
move (files of (entire contents of folder strFilepath) whose name ends with "_it_carta") to folder (strFilepath & "it")
end tell
修改
set folderNameList to {"ro", "ingl", "es", "it", "fr", "port"}
tell application "Finder"
set strFilepath to (get selection) as text
repeat with folderName in folderNameList
set newFolder to POSIX path of (strFilepath & folderName) & "/"
do shell script "mkdir -p " & (quoted form of newFolder) & "{\"A4\",\"carta\"}"
end repeat
set allFiles to entire contents of folder strFilepath
-- not clear on your move command
move (files of (entire contents of folder strFilepath) whose name ends with "_it_carta") to folder (strFilepath & "it")
end tell