Oft hat man Shellscripte die folgende Syntax haben:
Befehl Infile Outfile
also nach ihrem Aufruf als Parameter eine Inputdatei und eine Outputdatei erwarten, meist mit unterschiedlichen Dateiendungen.
Je nachdem wieviele Dateien umgewandelt werden sollen kann es recht lästig sein das Script x-mal aufzurufen und das Kommando anzupassen.
Hier kann man wunderbar Apple Script ins Spiel bringen. Aus genau so einer Aufgabenstellung heraus ist auch die Idee zu diesem Script entstanden.
Es ging dabei um die Umwandlung von *.dvi-Dateien in *.pdf-Dateien.1.
on SuchenUndErsetzen(derText, SuchText, Ersatztext)
set AppleScript's text item delimiters to the SuchText
set the itemListe to every text item of derText
set AppleScript's text item delimiters to the Ersatztext
set derText to the itemListe as string
set AppleScript's text item delimiters to ""
return derText
end SuchenUndErsetzen
try
tell application "Finder" to set the source_folder to (choose folder) as alias
end try
tell application "Finder"
set these_files to every file of folder source_folder -- whose name contains ".dvi"
end tell
repeat with i from 1 to the count of these_files
set this_file to (item i of these_files as string)
set this_info to info for this_file
set theDatei to this_file
set a to (POSIX path of (theDatei) as string)
-- get this_info
set SuchListe to {".dvi"}
set ErsatzListe to {"."}
set OriginalText to a
repeat with i from 1 to (count of SuchListe)
set SuchText to item i of SuchListe
set Ersatztext to item i of ErsatzListe
set OriginalText to SuchenUndErsetzen(OriginalText, SuchText, Ersatztext)
end repeat
set thePfad to OriginalText
-- get thePfad
set theSrcFile to thePfad & "dvi"
-- get theSrcFile
set theOutFile to thePfad & "pdf"
-- get theOutFile
set Befehl to "voller/Pfad/zum/script "
set Exec to Befehl & theSrcFile & " " & theOutFile
-- display dialog Exec
do shell script Exec
end repeat
Das Script muss natürlich entsprechend angepasst werden, wo es nötig ist (Dateiendungen, Pfad zum Befehl/Script).
Ausserdem empfiehlt es sich natürlich statt “do shell script” sich das Ganze erstmal per “display dialog” anzeigen zu lassen um sicher zu gehen dass man keinen Murks gemacht hat.
- 1