Help for a newbie

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

Grüß Dich Thomas,

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))

Grüße aus und nach Deutschland :wink:

THX.

Yes, this was what I am looking for.

The part… return quoted form of (POSIX path of (folderfile as alias))
returns… ‘’

Does it matter that the quotes are there? Can I use this in an do shell part? I guess the rest is easy.

  • do shell which tells terminal to “unrar -options ”
  • delete subfolder
  • run again or end if no more subfolders available

IF… you have the time, I would be very thankful for it :wink: I have 2 exams shortly and simly not the time right now to do it myself.

Hi Thomas,

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 :slight_smile: 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?


Enter password (will not be echoed):

Maybe you can find out why? I think it’s a bug…
See http://www.robertvenema.nl/journal/archive/howto-command-line-unrar-on-mac-os-x/ for how I started.

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…