Abrufen des Unix-Pfads mehrerer Dateien / Ordner im Automator-Dienst

525
COOL_IRON

Ich möchte den Pfad (mehrerer) Dateien (s, Ordner) im Automator-Dienst abrufen, indem Sie sie im Finder auswählen und dann im Shell-Befehl verwenden.

Ich habe schon so etwas:

AppleScript starten:

on run  tell application "Terminal" activate do script with command "clamscan --bell -i " & POSIX path of input end tell 

Endlauf

Dies funktioniert, aber nur für eine Datei oder einen Ordner und es nicht konvertieren /path/file with spaceszu /path/file\ with\ spaces.

Also, wie kann ich das beheben?

1

2 Antworten auf die Frage

0
wch1zpink

Dies funktioniert für mich mit der neuesten Version von Sierra

property posixPathofSelectedFinderItems : {} property QposixPathofSelectedFinderItems : {} -- stores the selected files in the active finder window -- in the variable "these_items" tell application "Finder" set these_items to the selection end tell  -- returns the Posix Path of each of those files and  -- stores all of that info in the "posixPathofSelectedFinderItems" -- as a list repeat with i from 1 to the count of these_items set this_item to (item i of these_items) as alias set this_info to POSIX path of this_item set end of posixPathofSelectedFinderItems to this_info end repeat  repeat with i from 1 to number of items in posixPathofSelectedFinderItems set this_item to item i of posixPathofSelectedFinderItems set this_item to quoted form of this_item set end of QposixPathofSelectedFinderItems to (this_item & " ") end repeat tell application "Terminal" activate do script with command "clamscan --bell -i " & items of QposixPathofSelectedFinderItems end tell set posixPathofSelectedFinderItems to {} set QposixPathofSelectedFinderItems to {} 
Das OP verwendet das `do script` _command_ von Terminal und nicht das` do shell script` _command_ von AppleScript. Die unmittelbare Frage, die ich sehe, ist Ihre Antwort, wenn mehr als eine Datei ausgewählt wird und viele Dateien ausgewählt werden, während die Option _bell_option_ des Clamscan-Befehls sozusagen klingelt, wie soll man wissen, welche von den vielen ausgewählten Dateien ist die infizierte Datei? "-i", mit dem infizierte Dateien gedruckt werden, ist in einem "do shell script" _command_ unbrauchbar, es sei denn, Sie setzen _output_ auf eine _variable_ und analysieren es dann etwas, aber nicht in "do script" _command_ von Terminal. Etwas zum Nachdenken! user3439894 vor 6 Jahren 1
Danke für das Heads-up. Ich arbeite gerade an einem anderen Beitrag, aber ich werde in Kürze auf diesen zurückkommen und die notwendigen Änderungen vornehmen wch1zpink vor 6 Jahren 0
Der letzte Befehl für die Ausgabe an die Shell muss folgendermaßen lauten: clamscan -I —bell '/ path / file1' '/ path / file 2' etc COOL_IRON vor 6 Jahren 0
Das Problem wurde behoben. Der Code wurde aktualisiert wch1zpink vor 6 Jahren 0
Ihre Antwort hat nicht benötigte Eigenschaften, die Sie einstellen ** und ** nicht-einstellbare, nicht benötigte mehrfache "repeat" _loops_. Das OP verwendet ** Automator ** und ein ** Run AppleScript ** _action_, so dass die einzige _variable_, und es muss keine `property` sein, dass` theItemsToScanList` als `list` und nur eine ist `repeat` _loop_, um die` Elemente der Eingabe 'darin zu verarbeiten, mit einer einzigen _Befehlszeile innerhalb des `repeat` _loop_. Sie verwenden 21 Zeilen von _code_, wobei 8 Zeilen von _code_ zu dem ** Run AppleScript ** _acton_ hinzugefügt werden können, um das OP-Ziel zu erreichen. user3439894 vor 6 Jahren 0
0
user3439894

Da Sie dies in Automator mit einem AppleScript- Acton ausführen ausführen, wird dies das tun, was Sie brauchen:

on run   set theItemsToScanList to {} repeat with i from 1 to count input set end of theItemsToScanList to quoted form of (POSIX path of (item i of input as string)) & space end repeat  tell application "Terminal" activate do script with command "clamscan --bell -i " & theItemsToScanList end tell  end run 

Es ist nicht nötig, die Dinge zu komplizieren und durch das Rigmarole zu gehen, das in der anderen Antwort gezeigt wird!


Oder wenn Sie sich für ein einfaches AppleScript- Skript / eine einfache Anwendung entscheiden, wird dies das tun, was Sie brauchen:

set theseItems to application "Finder"'s selection  set theItemsToScanList to {} repeat with i from 1 to count theseItems set end of theItemsToScanList to quoted form of (POSIX path of (item i of theseItems as string)) & space end repeat  tell application "Terminal" activate do script with command "clamscan --bell -i " & theItemsToScanList end tell 

Hinweis: Das Beispiel Applescript - Code oben ist nur, dass und beinhaltet keine Fehlerbehandlung wie es angemessen / erforderlich / wanted sein, ist die Beweislast, wenn der Benutzer eine beliebige hinzufügen Fehlerbehandlung für jeden Beispielcode vorgestellt und oder Code durch die selbst geschrieben .