Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 05.02.2002 - 13:18 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hallo scripters
obiges script von Sal Soghoian läuft manchmal durch, hängt sich jedoch zu 80 % auf, wenn Unterordner im Hauptfolderfolder drin sind. Wieso geht's manchmal und manchmal nicht ???
Hier noch das script:
-- Replace Text in Item Names
-- ©1998 Sal Soghoian, Apple Computer
tell application "Finder"
activate
display dialog "Search and replace in:" buttons {"File Names", "Folder Names", "Both"} default button 3
set the search_parameter to the button returned of the result
if the search_parameter is "File Names" then
set the display_parameter to "file"
else if the search_parameter is "Folder Names" then
set the display_parameter to "folder"
else
set the display_parameter to "file and folder"
end if
set the source_folder to choose folder with prompt "Folder containing " & the display_parameter & "s to process:"
repeat
display dialog "Enter text to find in " & the display_parameter & " names:" default answer ""
set the search_string to the text returned of the result
if the search_string is not "" then exit repeat
end repeat
repeat
display dialog "Enter replacement text:" default answer ""
set the replacement_string to the text returned of the result
if the replacement_string contains ":" then
beep
display dialog "A file or folder name cannot contain a colon ( ."
else
exit repeat
end if
end repeat
display dialog "Replace ³" & the search_string & "² with ³" & the replacement_string & "² in every " & the display_parameter & " name?"
display dialog "Include nested folders?" buttons {"Cancel", "Included Nested", "This Folder Only"} default button 3
set the search_level to the button returned of the result
if the search_parameter is "Both" then
if the search_level is "This Folder Only" then
set the item_list to (every item of the source_folder whose name contains the search_string) as list
else
set the item_list to (every item of the entire contents of the source_folder whose name contains the search_string) as list
end if
else if the search_parameter is "Folder Names" then
if the search_level is "This Folder Only" then
set the item_list to (every folder of the source_folder whose name contains the search_string) as list
else
set the item_list to (every folder of the entire contents of the source_folder whose name contains the search_string) as list
end if
else if the search_parameter is "File Names" then
if the search_level is "This Folder Only" then
set the item_list to (every file of the source_folder whose name contains the search_string) as list
else
set the item_list to (every file of the entire contents of the source_folder whose name contains the search_string) as list
end if
end if
repeat with this_item in the item_list
set this_item to the contents of this_item
set the item_name to the name of this_item
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of the item_name
set AppleScript's text item delimiters to the replacement_string
set the new_item_name to the item_list as string
set AppleScript's text item delimiters to ""
try
set the name of this_item to the new_item_name
on error error_msg
set the source_folder_path to my extract_parent_folder_path_from(this_item)
try
reveal (the source_folder_path & the new_item_name) as string as alias
on error
reveal this_item
set error_msg to "The new name: " & return & the new_item_name & return & "contains too many characters to rename this file."
end try
beep
display dialog error_msg buttons {"Stop", "Continue"} default button 2
if the button returned of the result is "Stop" then return "user canceled"
set selection to {}
end try
end repeat
end tell
on extract_parent_folder_path_from(the_filepath)
set the_filepath to the_filepath as text
set x to the offset of ":" in (the reverse of every character of the_filepath) as string
set the_filepath to (characters 1 thru -(x) of the_filepath) as text
end extract_parent_folder_path_from
beep 2
the item_list
tAmbo |
|
Nach oben |
|
 |
Busyman •-->


Anmeldedatum: 16.09.2001 Beiträge: 64 Wohnort: Ostwestfalen
|
Verfasst am: 05.02.2002 - 16:40 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hi tAmbo,
habe mir das Script jetzt aus Zeitgründen nicht ganz durchgelesen, aber es benutzt den Befehl "entire contents". Und dieser gilt als sehr unsicher. Denn manchmal funzt er, bei größeren Ordnergrößen schmiert er aber schon gerne einmal ab. Daher hat der nette Snow eine viel genialere Aktion entwickelt, die Unterordner sicher abarbeiten kann. Ich habe sie in meinem iTunes-O-Mat verwendet, hier ist er:
[font=geneva]-- ©2002 by Martin Michel
-- Email: busyman@macnews.de
property changedFiles : 0
on run
with timeout of 6000 seconds
set changedFiles to 0
set theFileList to (choose folder with prompt ¨
"Bitte wählen Sie einen Ordner aus:" ) as list
repeat with theFile in theFileList
File_or_Folder(theFile)
end repeat
if changedFiles > 0 then
tell application "Finder"
activate
display dialog ¨
( "Es wurden " & changedFiles as string) & " Dateien erfolgreich umgewandelt." buttons { "Super" } default button 1 with icon note giving up after 10
end tell
end if
end timeout
end run
on open theFileList
with timeout of 6000 seconds
set changedFiles to 0
repeat with theFile in theFileList
my File_or_Folder(theFile)
end repeat
if changedFiles > 0 then
tell application "Finder"
activate
display dialog ¨
( "Es wurden " & changedFiles as string) & " Dateien erfolgreich umgewandelt." buttons { "Super" } default button 1 with icon note giving up after 10
end tell
end if
end timeout
end open
-- Hier beginnt Snows Routine, die auch Unterordner abarbeitet
on File_or_Folder(theFile)
set theInfo to info for theFile
if folder of theInfo then
tell application "Finder"
set FolderList to every item of theFile
end tell
repeat with theFolder in FolderList
set theFolder to theFolder as alias
my File_or_Folder(theFolder)
end repeat
else
my ProcessIt(theFile)
end if
end File_or_Folder
on ProcessIt(theFile)
tell application "Finder"
set changedFiles to changedFiles + 1
set creator type of theFile to "hook"
set file type of theFile to "MPG3"
end tell
end ProcessIt[/font]
Wenn Du genau angeben würdest, welchen text Du wie ändern möchtest, könnte man den iTunes-O-Mat so umbauen, daß er Dateinamen verändert.
Gruß,
Busyman |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 05.02.2002 - 17:56 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hi busyman
danke für die schnelle Antwort; es geht darum, in foldern- und subfoldern die Dateinamen von html-dateien auf einen Schlag ändern zu können...
Gruss, tAmbo |
|
Nach oben |
|
 |
Busyman •-->


Anmeldedatum: 16.09.2001 Beiträge: 64 Wohnort: Ostwestfalen
|
Verfasst am: 05.02.2002 - 18:07 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hi tAmbo,
jetzt sind wir ja schon weiter :biggrin:
Nur mußt Du noch erwähnen, was GENAU geändert werden soll: Soll das Suffix ".html" angehängt oder gelöscht werden, soll der Name in einer bestimmten Weise gekürzt, verlängert, nummeriert, oder sonstwie geändert werden? Fragen über Fragen :)
Gruß,
Busyman |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 06.02.2002 - 02:09 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hi Buysiman
also, praktisch wäre ein script, mit dem man den austausch von jpgs auf webseiten "automatisieren" könnte, will heissen: es enthält einen replace oder rename-dialog für Dateinamen, nicht creators/type; sodass die ganzen (standardisierten) html-seiten nur ein einziges Mal geschrieben werden müssen, da das applescript dann für die einzelnen Seiten die Zuteilungen übernimmt; anstelle von z.b. <alpha> der "Masterseite "nun dann der dateiname des jps , z.b. >hans< das andere mal > peter<, etc eingegeben werden könnte...dies auch beim ahref.
Darf ruhig auchals hans 1, hans 2 passieren .....idealerweise funktioniert dies über mehrere folder und unterfolder...
mit dem obigen script von Soghoian lief das teilweise, aber eben nicht sauber, bei den nestled foldern...
Probiere das von Dir gepostete script mal aus,
Gruss, tAmbo |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 06.02.2002 - 02:14 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Korrektur
anstelle von z.b. von <alpha> der "Masterseite "nun dann der dateiname des jps , z.b. >hans< das andere mal > peter<, etc eingegeben werden könnte...dies auch beim ahref.
Ist beim "Vorschaulesen" rausgefallen
tAmbo |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 06.02.2002 - 12:49 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
komisch: wenn ich nun meine Korrektur im thread anschaue, hat sich da nichts verändert, gehe ich auf antworten, sehe ich meine richtige Korrektur *staunstaun*
hatte da alpha in brackets geschrieben, ist das wohl ein html-befehl????
also ohne brackets.....so war's gemeint:
-->da das applescript dann für die einzelnen Seiten die Zuteilungen übernimmt; anstelle von z.b. "alfa" der "Masterseite "nun dann der dateiname des jps , z.b. >hans< das andere mal > peter<, etc eingegeben werden könnte...dies auch beim ahref.
in der Vorschau nun korrekt,
tAmbo |
|
Nach oben |
|
 |
Busyman •-->


Anmeldedatum: 16.09.2001 Beiträge: 64 Wohnort: Ostwestfalen
|
Verfasst am: 06.02.2002 - 17:00 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Hi tAmbo,
ich habe mich mal kurz hingesetzt und das Script umgeschrieben. Es funktioniert, ist aber noch keine Luxuslösung, da bräuchte ich mehr Zeit. Das Script berücksichtigt immer auch alle Dateien, die sich in Unterordnern befinden. Den Namen von Ordnern und Unterordnern berücksichtigt es aber nicht. Es verändert nur Dateinamen. Vielleicht probierst Du es mit einem Probeordner einfach mal aus.
Gruß,
Martin
[font=geneva]property searchText : {}
property replaceText : {}
on open theList
with timeout of 6000 seconds
set searchText to ""
set replaceText to ""
tell application "Finder"
activate
display dialog "Achtung!" & return & return & "Das Script verändert auch den Text aller Dateien, die sich in Unterordnern befinden!" buttons "Okay" default button 1 with icon caution
repeat
display dialog "Text, der ersetzt werden soll:" default answer ""
set searchText to the text returned of the result
if the searchText is "" then
beep
display dialog "Sie haben keinen Text eingegeben!"
else
exit repeat
end if
end repeat
repeat
display dialog "Text, der stattdessen eingesetzt werden soll:" default answer ""
set replaceText to the text returned of the result
if the replaceText contains ":" then
beep
display dialog "Namen von Dateien und Ordnern dürfen keine Doppelpunkte enthalten!"
else
exit repeat
end if
end repeat
display dialog "Soll der Text ³" & the searchText & "² wirklich durch den Text ³" & the replaceText & "² in allen Dateinamen ersetzt werden?"
repeat with theItem in theList
my File_or_Folder(theItem)
end repeat
end tell
end timeout
end open
on File_or_Folder(theItem)
set theInfo to info for theItem
if folder of theInfo then
tell application "Finder"
set FolderList to every item of theItem
end tell
repeat with theFolder in FolderList
set theFolder to theFolder as alias
my File_or_Folder(theFolder)
end repeat
else
my ProcessIt(theItem)
end if
end File_or_Folder
on ProcessIt(theItem)
tell application "Finder"
set the itemName to the name of theItem
set AppleScript's text item delimiters to the searchText
set the item_list to every text item of the itemName
set AppleScript's text item delimiters to the replaceText
set the newitemName to the item_list as string
set AppleScript's text item delimiters to ""
if (count of newitemName) is greater than 31 then
display dialog ( "Der neue Dateiname für die Datei:" & return & return & theItem as string) & return & return & "hätte mehr als 31 Zeichen und kann daher nicht verwendet werden." buttons "Okay" default button 1 with icon caution
else
set the name of theItem to the newitemName
end if
end tell
end ProcessIt[/font]
---
Die neue Software von Busyman, erstellt im AppleScript Studio:
Link-O-Mat 1.1 E (Mac OS X) |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 06.02.2002 - 17:13 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Danke Martin,
probiere es mal gleich aus
tAmbo |
|
Nach oben |
|
 |
tAmbo •-->

Anmeldedatum: 31.01.2002 Beiträge: 25
|
Verfasst am: 06.02.2002 - 18:41 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
:cheesy: bist ja gut, Martin,
Läuft über 10 Unterordner, als Droplet und im Finder Pop (im 9.2)!!
habe noch am Schluss ein "beep" eingefügt, damit ich merke, wenn das script beendet ist.... im Osa-menü dagegen liefs bei mir nicht.... was mich jedoch nicht weiter stört...
Danke, tAmbo |
|
Nach oben |
|
 |
Busyman •-->


Anmeldedatum: 16.09.2001 Beiträge: 64 Wohnort: Ostwestfalen
|
Verfasst am: 06.02.2002 - 19:00 Titel: Replace Text in item Names, manchmal läufts.... |
|
|
Es kann auch gar nicht im OSA-Menü laufen :biggrin:
Denn es ist ein Droplet, funzt nur, wenn man Dateien darauf zieht :)
Wollte man, daß es auch im OSA-Menü funzt, müßte man noch einen on run-Handler einbauen, der beim Öffnen des Scripts den Benutzer nach einem Ordner oder einer Datei fragt, der oder die abgearbeitet werden soll.
Funzt übrigens auch unter OS X :cool:
Gruß,
Busyman
(Geändert von Busyman um 18:02 Uhr am 6 Feb. 2002) |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
Powered by phpBB © 2001, 2002 phpBB Group Deutsche Übersetzung von phpBB.de
|
|
|