Hi,
kann mir einer der erfahrenen Kollegen hier helfen...
Ich möchte in dem Script, den "choose folder" Befehl gegen einen festen Pfad einstellen:
ohne Auswahl sollte der nachfolgende Pfad verwendet werden.
/Application/Testjob
Das script macht nichts anderes als alles Dateien dieses Verzeichnis anzuzeigen.
Vielen Dank im Voraus
Code:
set the_list to ""
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of folder (choose folder)
repeat with entry in file_list
set the_list to the_list & nl & entry
end repeat
display alert the_list
end tell
Ich bin zwar nicht erfahren, aber dafür scheint es zu reichen
set the_list to ""
set my_folder to "Application:Testjob" as alias
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of my_folder
repeat with entry in file_list
set the_list to the_list & nl & entry
end repeat
display alert the_list
end tell
Hallo Wakko,
Danke für den Versuch... klappt leider nicht.
Testjob ist ein Verzeichnis in Applications...
Ich erhalte einen Scriptfehler:
"Die Datei „Application:Testjob“ wurde nicht gefunden."
ich meine ich habe das auch bereits versucht, leider erfolglos
Magst du noch einen Versuch starten ;-)
andere sind auch herzlich Willkommen.
Vielen Dank
Ja Du hast Recht, das klappt so nur im User Ordner. Für den Programme Ordner musst Du noch den Namen der Festplatte davor packen:
Code:
set the_list to ""
set my_folder to "MacintoshFD:Applications:Testjob" as alias
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of my_folder
repeat with entry in file_list
set the_list to the_list & nl & entry
end repeat
display alert the_list
end tell
So funktioniert es auf jeden Fall bei mir. Nimm mal dein Programm mit dem "choose folder" und stelle im Script-Editor unter Darstellung-> Protokoll einblenden ein und dort den Punkt Antworten. Da kannst Du dann genau sehen, welchen Pfad Du unter "choose folder" gewählt hast.
Hi
Versuch es mal damit:
Code:
set the_list to ""
set my_folder to (path to applications folder as text) & "Testobjekt" as alias
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of my_folder
repeat with entry in file_list
set the_list to the_list & nl & entry
end repeat
display alert the_list
end tell
Damit musst Du Dir keine Gedanken um den Namen der Festplatte machen.
Daneben gibt es z.B. noch:
Code:
path to home folder
path to desktop
path to me
Letzteres ist ganz praktisch, wenn das Script als "Programm" abgespeichert wurde. "path to me" gibt den Pfad zu zu dem Ordner zurück, in dem das Script (die App) gestartet wurde.
Gruss
lifeflow
Hallo,
ich wollte nochmals Danke sagen, es klappt, TipTop
Hatte bereits gepostet aber irgendwie anscheinend nicht auf absenden geklickt.
Da ich ja ziemlicher Anfänger mit dem Thema bin, muss ich mir alles aus dem Internet "abschauen" bzw. auf Hilfe hoffen...
Jetzt habe ich ein weiteres Problem erkannt.
Die Dateien werden mit obigen Script über "display alert" angezeigt. Das klappt auch soweit gut, nur kann mein 13" macbook leider nur einen Teil der Daten anzeigen... Das Fenster kann nicht groß genug angezeigt werden, (auf dem kleinem Display) da ich teilweise über 50 und mehr Dateien aufliste.
Ich brauche also soetwas wie eine neue Seite, also zB. Auflisten und ab 20 Einträgen kann ich mit "weiter" die nächsten Einträge anzeigen.
Ich hoffe ich habe mich verständlich ausgedrückt.
Vorab Danke für Hilfe oder Ideenansätze.
Hi
Hier ist mal ein erster schneller Entwurf. Benötigt aber noch etwas Feinarbeit. Teste das erst mal so. Wenn es das ist, was Du Dir vorgestellt hast, dann mache ich das morgen fertig.
Code:
set the_list to ""
set my_folder to (path to applications folder as text) & "Testobjekt" as alias
set nl to ASCII character 10
set the_offset to 0 as number
tell application "Finder"
set file_list to name of every file of my_folder
set cItems to count of items in file_list
if cItems > 19 then
set ccounter to 20
else
set ccounter to cItems
end if
repeat
set the_list to ""
set i to 0
repeat ccounter times
set i to i + 1
set the_list to the_list & nl & item (the_offset + i) of file_list
end repeat
display dialog the_list with title "Items " & the_offset & " to " & (the_offset + 20) & " of " & cItems buttons {"Zurück", "Vor", "Abbruch"} default button 3
set DlogResult to result
if button returned of result = "Zurück" then
if the_offset > 19 then
set the_offset to the_offset - 20
else
set the_offset to 0
end if
else if button returned of result = "Vor" then
set the_offset to the_offset + 20
else if button returned of result = "Abbruch" then
exit repeat
end if
if the_offset + 20 > cItems then
set the_offset to cItems - 20
end if
end repeat
end tell
ich weiss ja nicht, was Du mit dem Inhalt machen willst, aber Du könntest Dir ja einfach den Ordner mit:
Code:
open folder my_folder
öffnen. Oder mit:
Code:
choose folder default location my_folder
Die Ordnerauswahl mit deinem Ordner als Standard öffnen.
Hi
Hier nun das "fertige" Script. Es erzeugt eine Dialogbox wie diese (Hier beispielhaft der "Programme" Ordner):
[
attachment=34790]
Der Code:
Code:
set the_list to ""
set my_folder to (path to applications folder as text) & "Testobjekt" as alias
set nl to ASCII character 10
set the_offset to 0 as number
tell application "Finder"
set file_list to name of every file of my_folder
set cItems to count of items in file_list
if cItems > 19 then
set ccounter to 20
else
set ccounter to cItems
end if
repeat
set the_list to ""
set i to 0
repeat ccounter times
set i to i + 1
set the_list to the_list & item (the_offset + i) of file_list & nl
end repeat
display dialog the_list with title "Items " & the_offset & " to " & (the_offset + ccounter) & " of " & cItems buttons {"Zurück", "Vor", "Abbruch"} default button 3 with icon "Finder"
set DlogResult to result
if button returned of result = "Zurück" then
if the_offset > 19 then
set the_offset to the_offset - 20
else
set the_offset to 0
end if
else if button returned of result = "Vor" then
if the_offset + 20 < cItems - 20 then
set the_offset to the_offset + 20
else
if cItems > 20 then
set the_offset to cItems - 20
else
set the_offset to 0
end if
end if
else if button returned of result = "Abbruch" then
exit repeat
end if
end repeat
end tell
Falls das aber tatsächlich nur für ein einfaches Directory Listing benötigt wird, dann wäre die Variante von @Wakko wesentlich einfacher im Handling.
Hi ilifeflow,
das sieht schon Super aus. Du bist da anscheinend echt fortgeschritten.
eine Anmerkung:
wenn ich zB. 25 Dateien auflisten möchte, dann zeigt er die ersten 20 an
also Datei 1-20
wenn ich weiter drücke, dann zeigt er mir die Dateien
5-25 an.
geht es dass die Daten nicht doppelt angezeigt werden.
also 1-20 und mit weiter nur noch die Dateien 21-15
nochmals Vielen Dank für deine Hilfe.
Viele Grüße
Ja, das geht auch. Ich habe ausserdem gleich noch eine Warnung eingebaut, falls der Ordner keine Dateien enthält:
[
attachment=34806]
Hier ist der Code:
Code:
set the_list to ""
set my_folder to (path to applications folder as text) & "Testobjekt" as alias
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of my_folder
set cItems to count of items in file_list
set the_offset to 0 as number
if cItems = 0 then
display dialog "Der Ordner enthält keine Dateien!" buttons {"OK"} with icon caution
return
end if
if cItems > 19 then
set ccounter to 20
else
set ccounter to cItems
end if
repeat
set the_list to ""
set i to 0
set disp to 0 as number
repeat ccounter times
set i to i + 1
if the_offset + i ≤ cItems then
set the_list to the_list & item (the_offset + i) of file_list & nl
set disp to disp + 1
else
set the_list to the_list & "" & nl
end if
end repeat
display dialog the_list with title "Items " & the_offset + 1 & " to " & (the_offset + disp) & " of " & cItems buttons {"Zurück", "Vor", "Abbruch"} default button 3 with icon "Finder"
set DlogResult to result
if button returned of result = "Zurück" then
if the_offset > 19 then
set the_offset to the_offset - 20
else
set the_offset to 0
end if
else if button returned of result = "Vor" then
if the_offset < cItems then
set the_offset to the_offset + 20
if the_offset > cItems then
set the_offset to the_offset - 20
end if
end if
else if button returned of result = "Abbruch" then
exit repeat
end if
end repeat
end tell
Hi,
funktioniert perfekt. Jetzt gäbe es nur noch Schönheitskorrekturen ;-)
aber ich will ja nicht unverschämt sein.
Die Schaltfläche vor und zurück
- sollten nur angezeigt werden, wenn auch mehr als 20 Einträge da sind.
- bei mehr als 20 Einträge sollte auf der ersten Seite kein "zurück" sein (gibt ja kein zurück auf der ersten Seite)
- im Gegenzug sollte auf der letzten Seite kein "weiter" mehr geben, da am Ende, sondern nur zurück
Ich bin immer wieder beeindruckt, wie Ihr das "programmieren" könnt. Ich habe bisher verschieden Sprache versucht, aber scheitere dann an den "Interessanten" Sachen und gebe auf :-(. Ich glaube mir fehlen dafür bestimmte "Windungen" im Kopp
Danke und Grüße
Hi
Versuch es mal damit:
Code:
set the_list to ""
set my_folder to (path to applications folder as text) & "Testobjekt" as alias
set nl to ASCII character 10
tell application "Finder"
set file_list to name of every file of my_folder
set cItems to count of items in file_list
set the_offset to 0 as number
if cItems = 0 then
display dialog "Der Ordner enthält keine Dateien!" buttons {"OK"} with icon caution
return
end if
if cItems > 19 then
set ccounter to 20
else
set ccounter to cItems
end if
repeat
set the_list to ""
set i to 0
set disp to 0 as number
repeat ccounter times
set i to i + 1
if the_offset + i ≤ cItems then
set the_list to the_list & item (the_offset + i) of file_list & nl
set disp to disp + 1
else
set the_list to the_list & "" & nl
end if
end repeat
if cItems < 20 then
display dialog the_list with title "Items " & the_offset + 1 & " to " & (the_offset + disp) & " of " & cItems buttons {"OK"} with icon "Finder"
else
if the_offset < 20 then
display dialog the_list with title "Items " & the_offset + 1 & " to " & (the_offset + disp) & " of " & cItems buttons {"Vor", "Abbruch"} with icon "Finder"
else
if the_offset + 20 is greater than cItems then
display dialog the_list with title "Items " & the_offset + 1 & " to " & (the_offset + disp) & " of " & cItems buttons {"Zurück", "Abbruch"} with icon "Finder"
else
display dialog the_list with title "Items " & the_offset + 1 & " to " & (the_offset + disp) & " of " & cItems buttons {"Zurück", "Vor", "Abbruch"} with icon "Finder"
end if
end if
end if
set DlogResult to result
if button returned of result = "Zurück" then
if the_offset > 19 then
set the_offset to the_offset - 20
else
set the_offset to 0
end if
else if button returned of result = "Vor" then
if the_offset < cItems then
set the_offset to the_offset + 20
if the_offset > cItems then
set the_offset to the_offset - 20
end if
end if
else if button returned of result = "Abbruch" or button returned of result = "OK" then
exit repeat
end if
end repeat
end tell
Das Ganze ist etwas tricky, weil man in Applescript nicht so einfach Dialogboxen im laufenden Betrieb verändern kann. Zumindest ist mir aus dem Hut kein Weg bekannt. Ich habe das jetzt mal über 4 unterschiedliche Dialogboxen gelöst. Diese werden unter folgenden Umständen eingeblendet:
1. Es sind insgesamt weniger als 20 Objekte anzuzeigen: die Dialogbox enthält nur einen einzigen "OK" Button. "OK" deshalb, weil es nichts abzubrechen gibt. Die Anzeige steht, mehr ist eh nicht möglich.
2. Der Zähler befindet sich am Anfang der Liste: Es wird eine Dialogbox ohne "Zurück" Button verwendet. Statt "OK" gibt es wieder einen "Abbruch" Button.
3. Der Zähler befindet sich am Ende der Liste: die verwendete Dialogbox hat keinen "Vor" Button. Auch hier gibt es "Abbruch" statt "OK".
4. Der Zähler befindet sich irgendwo dazwischen: die bekannte Dialogbox mit den 3 Buttons "Zurück", "Vor" und "Abbruch" wird angezeigt.
Es gibt jedoch einen Schönheitsfehler. Die Position der Buttons ist nicht frei wählbar. Zumindest wüsste ich nicht, wie. Das hat zur Folge, dass bei der Dialogbox ohne "Vor" Button der "Zurück" Button an dessen Position rutscht. Dafür habe ich leider keine Lösung. Ich habe versucht, den leeren Raum mit einem leeren Button ohne Funktion zu füllen (als Platzhalter), aber das sieht einfach nicht gut aus. Aber probier das ruhig mal selbst aus. Wenn es Dir so nicht gefällt, dann kann ich Dir den Platzhalter einbauen.
Zum Thema Programmieren, ich bin mit Basic auf dem Commodore VC-20 gestartet und habe mich später eher mit Scriptsprachen beschäftigt (z.B. Rexx auf OS/2). In Applescript könnte man vieles sicher eleganter abhandeln als ich es tue, aber letztlich funktioniert das meiste und das reicht mir aus
Gruss
lifeflow
Hi,
das ganze ist so wie es ist absolut in Ordnung!!
Bin wunschlos glücklich.
Nochmals Vielen Dank für dein Hilfe.
Ich werde bestimmt bald wiederkommen ;-)
Keine Ursache! Melde Dich einfach, wenn Du noch etwas brauchst