Wieso alias list?

Kaito

Aktives Mitglied
Thread Starter
Dabei seit
31.12.2005
Beiträge
7.093
Reaktionspunkte
1.844
Von http://stackoverflow.com/questions/...hing-is-a-directory-or-a-file/6881524#6881524 habe ich mir folgendes abgeschaut:

Code:
on run {input, parameters}
	--tell application "Finder" to set input to (selection) as alias list
	
	tell application "System Events"
		repeat with anItem in input
			if anItem is package folder or kind of anItem is "Folder" or kind of anItem is "Volume" then
				set dir_path to (POSIX path of (contents of anItem))
				set qdir_path to quoted form of dir_path
				my CD(qdir_path)
			else
				set dir_path to (POSIX path of (container of (contents of anItem) as string))
				set qdir_path to quoted form of dir_path
				my CD(qdir_path)
			end if
			delay 0.1
		end repeat
	end tell
end run
Ich frage mich wozu ist die erste Zeile gut? Ich erkenne im Verhalten keinen Unterschied ob mit oder ohne.
Eine andere Frage wären noch je die beiden Zeilen mit den dir_path Variablen. Das kann ich nicht in eine schreiben,
set qdir_path to quoted form of (POSIX path of (container of (contents of anItem) as string))
resultiert in "cant make quoted form of posix path of alias", was mir nicht ganz sinnvoll erscheint, wenn es auf zwei Zeilen aufgeteilt doch funktioniert.
 
Zu 1.:

Die erste Zeile brauchst du, wenn das Skript nicht im Automator, sondern im AppleScript-Editor ausgeführt werden soll.

Zu 2.:

Das hat damit zu tun wie AppleScript mit Objekten und ihren Referenzen um geht. Mit repeat with anItem in input wird in anItem lediglich item x of input anstatt des entsprechenden Wertes gespeichert. Der entsprechende Wert wird erst durch durch ein explizites get abgerufen. So funktioniert es:

set
qdir_path to quoted form of (get POSIX path of container of contents of anItem)
 
1.) Super, dann lassen wir das gleich auskommentiert.
2.) Bei deiner Version lande ich am Ordner vor dem eigentlich ausgewählten. Aber danke, das gab den nötigen Anstoß zu dem funktionierenden:
set qdir_path to quoted form of (get POSIX path of (contents of anItem))
set qdir_path to quoted form of (get POSIX path of (container of (contents of anItem)) as string)

:)
 
Zurück
Oben Unten