Der Versuch eines Docklets

detto

Aktives Mitglied
Thread Starter
Dabei seit
22.08.2007
Beiträge
3.182
Reaktionspunkte
263
:moin:


Au weia,.. schon spät geworden.... :eek:
Nunja,....


Ich probier mich gerade an nem Docklet für Rar-Dateien, zum Entpacken.
So weit bin ich schon gekommen:
Code:
on open theFiles
	repeat with i from 1 to number of items of theFiles
		set curFile to item i of theFiles
		set CWD to POSIX path of ((path to curFile) as alias)
		display dialog "Passwort:" buttons {"OK"} default answer "" default button "OK"
		set thePassword to text returned of the result
		--
		try
			if thePassword is "" then
				do shell script "cd '" & CWD & "' && unrar x '" & curFile & "'"
			else
				do shell script "cd '" & CWD & "' && unrar x -p'" & thePassword & "''" & curFile & "'"
			end if
			display dialog "Entpackvorgang erfolgreich"
		on error
			display dialog "Abgebrochen durch Fehler"
		end try
		--
	end repeat
end open
Gespeichert hab ich das ganze als "Programm-Bundle".
Wenn jetzt eine Datei auf das Docklet fallen gelassen wird, öffnet sich folgende Fehlermeldung: http://xs225.xs.to/xs225/08113/bild_1588.png

Aber laut Zeile 4 wird doch korrekt in den POSIX Pfad umgewandelt? :confused:
 
Hallo,

Zeile 4:
An dieser Stelle hast Du ein Alias von der Datei. "path to" ist nicht notwendig, da das Alias den Pfad schon mitbringt. Das nochmalige ausweisen zu "as alias" ist somit auch nicht korrekt ;-)

Hier die Lösung:

Code:
on open theFiles
	repeat with i from 1 to number of items of theFiles
		set curFile to item i of theFiles
		set CWD to POSIX path of (curFile as string)
		display dialog "Passwort:" buttons {"OK"} default answer "" default button "OK"
		set thePassword to text returned of the result
		--
		try
			if thePassword is "" then
				do shell script "cd '" & CWD & "' && unrar x '" & curFile & "'"
			else
				do shell script "cd '" & CWD & "' && unrar x -p'" & thePassword & "''" & curFile & "'"
			end if
			display dialog "Entpackvorgang erfolgreich"
		on error
			display dialog "Abgebrochen durch Fehler"
		end try
		--
	end repeat
end open

Viele Grüße
 
Code:
on open theFiles
	set unRAR to do shell script "which unrar"
	repeat with i from 1 to number of items of theFiles
		set curFile to item i of theFiles
		set CWD to POSIX path of (curFile as string)
		display dialog "Passwort:" buttons {"OK"} default answer "" default button "OK"
		set thePassword to text returned of the result
		--
		try
			if thePassword is "" then
				do shell script "cd " & CWD & "; unRAR" & " x" & " curFile"
			else
				do shell script "cd " & CWD & "; unRAR" & " x -p" & thePassword & " curFile"
			end if
			display dialog "Entpackvorgang erfolgreich"
		on error
			display dialog "Abgebrochen durch Fehler"
		end try
		--
	end repeat
end open


Danke, soweit funktioniert das ganze schonmal. Jetzt hakts nur noch an dem eigentlichen Skript, dem do shell script.
Irgendwie bekomm ich egal was ich anstelle immer nur die on error-Meldung zu Gesicht. :confused:
Hab jetzt schon echt was mit hingefriemelt mit den ganzen " und & und Leerstellen, aber gebracht hats bisher nonnix. :rolleyes:


edit: Nicht einmal das hier
Code:
do shell script "cd " & CWD & " && /usr/bin/unrar x " & curFile
scheint zu funktionieren.
 
Zuletzt bearbeitet:
Hallo,

die Snytax Deinens Shell-Scripts habe ich nicht überprüft ;-)

Tipp:
Entferne den ganzen Try-Block und lasse Dir mittels "display dialog" Dein Aufruf ausgeben. Dann wirst Du schnell verstehen, warum es nicht funktioniert.

Viele Grüße
 
Alles klar!
Also er kann natürlich nicht in das Verzeichnis /Users/detto/Desktop/bla.rar wechseln. ;)
Ich muss also die Übeltäterzeile wieder ändern, die wo er das Verzeichnis des aktuellen Datei auslesen soll.

Code:
on open theFiles
	set unRAR to do shell script "which unrar"
	repeat with i from 1 to number of items of theFiles
		set curFile to POSIX path of item i of theFiles
[COLOR="Red"]		-- set CWD to POSIX path of curFile
                -- ^ hier soll er den Pfad von curFile in die variable CWD speichern.[/COLOR]
		display dialog "Passwort:" buttons {"OK"} default answer "" default button "OK"
		set thePassword to text returned of the result
		--
		if thePassword is "" then
			do shell script "cd " & CWD & " && " & unRAR & " x " & curFile
		else
			do shell script "cd " & CWD & " && " & unRAR & " x -p" & thePassword & " " & curFile
		end if
		--
	end repeat
end open

Lege ich CWD fest auf einen bestimmten Ordner (zB: set CWD to "~/Desktop") klappt alles, er entpackt sogar! :)
Hab jetzt schon zig Seiten gegoogled aber nicht rausbekommen können, wie man lediglich den Pfad, genau genommen bloß den Aufenthaltsort (parent directory?) einer Datei heraus bekommt.
 
Zuletzt bearbeitet:
Fast ;-)

Hier ein Beispiel:

Code:
tell application "Finder"
	set mutterOrdner to container of (choose file)
	display dialog "Ich bin der Mutter-Ordner:" & return & mutterOrdner as string
end tell

Beachte, dass "container of" eine Datei-Referenz erwartet. (alias)

Viele Grüße
 
In beiden Fällen (als alias oder POSIX) sagt er mir, "container of ... kann nicht gelesen werden". :confused:
 
Den Tell-Block darfst Du nicht unterschlagen:

Code:
tell application "Finder" to set mutterOrdner to container of meineDatei

Erst danach erzeugt Du den POSIX Pfad ;-)

Viele Grüße
 
Vielen Dank!!

Hab es endlich hinbekommen und bin denk ich wieder n Stückchen schlauer geworden in AppleScript.
Teilweise ist das zu Anfang wirklich ein Krampf, sofern man AS und die Shell miteinander nutzen möchte. Dauernde Umwandlung der Pfade usw. usf.

Hier das (vorerst) endgültige Skript/Droplet zum Entpacken von RAR-Dateien. (passwortgeschützte Dateien wurden noch nicht damit getestet)

Code:
on open theFiles
	set unRAR to do shell script "which unrar"
	repeat with i from 1 to number of items of theFiles
		tell application "Finder" to set parentDir to container of item i of theFiles
		set CWD to POSIX path of (parentDir as text)
		set curFile to POSIX path of item i of theFiles
		-- the path of the rar file = path of extracted content
		-- now check if password is needed and extract
		display dialog "Passwort:" buttons {"OK"} default answer "" default button "OK"
		set thePassword to text returned of the result
		if thePassword is "" then
			do shell script "cd " & CWD & " && " & unRAR & " x " & curFile
		else
			do shell script "cd " & CWD & " && " & unRAR & " x -p" & thePassword & " " & curFile
		end if
	end repeat
end open
 
Zurück
Oben Unten