Hi.
I am german, so please excuse all my writing errors…
I select a main folder. In that main folder are alot of folders (sub folders) which all contain some compressed files (all rar). How do I select the first subfolder and in that folder the first file? I don’t need a list because I want to unzip the files, move the new file to another location, delete the subfolder1, making the subfolder2 the new subfolder1 and so on.
The uncompressing will be done via terminal & unrar.
THX
I don’t know if I fully understood your workflow requirements, but here is some code that will ask you to choose a mainfolder and then returns the Posix path of the first file found in the first subfolder:
set mainfolder to choose folder with prompt "Bitte wählen Sie einen Ordner aus:" without multiple selections allowed
tell application "Finder"
set subfolder to first folder in mainfolder
set folderfile to first file in subfolder
end tell
return quoted form of (POSIX path of (folderfile as alias))
If you are working with paths on the shell, you should always quote them (sie in Anführungszeichen setzen). Otherwise, a path containing a space would be interpreted as two paths. Here is the complete script. It’s not elegant (I would not script it like that), but fulfills your requirements Please customize the options of the unrar command.
set mainfolder to choose folder with prompt "Bitte wählen Sie einen Ordner aus:" without multiple selections allowed
repeat
try
tell application "Finder"
set subfolder to first folder in mainfolder
set folderfile to first file in subfolder
end tell
set command to "unrar -options " & quoted form of (POSIX path of (folderfile as alias))
do shell script command
set command to "rm -r " & quoted form of (POSIX path of (subfolder as alias))
do shell script command
on error
exit repeat
end try
end repeat
So far so good. But some how it (unrar) doesn’t let me set a decryp-password. When the terminal asks for a password, is there a way to let Applescript tell the shell the password?
It would be also a good feature to see the script working. Right now even if working, it doesn’t show anything and I wonder if it is actually doing anything. And with enough files to keep the script working for hours…