Hi,
vorweg, ich bin kein großer Apple-Script Künstler
Somit bevorzuge ich es Auswertungen eines PDF-Dokuments mit einem kleinen Perl-Script auszuführen. Dazu habe ich ein Apple-Script zusammen gebastelt, welches mir den Plain-Text eines PDF’s in eine temp. Datei schreiben soll. Anschließend soll das Perlscript seinen Job durchführen und die Ergebnisse an das Apple-Script zurückgeben.
Hier mein Apple-Script
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
set this_type to ((type of theRecord) as string)
display alert this_type
if (this_type contains "PDF") then
display alert "PDF"
set thetext to plain text of theRecord
set oldDelims to AppleScript's text item delimiters -- save their current state
-- Text in temp. Datei schreiben
set target_file to (path to temporary items folder as text) & "dummy.dat"
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
set eof of the open_target_file to 0
write thetext to the open_target_file starting at eof
close access the open_target_file
-- temp. Datei mit perl-Script durchsuchen
set return_value to do shell script "/Users/boni/perl-Scripts/get_first_date_in_txt.pl \"" & target_file & "\" "
-- wenn String nicht gefunden wird Fehler ausgeben
if (return_value contains "error") then
display alert "Das Rechnungsdatum wurde im Document nicht gefunden"
else
display dialog (return_value as string)
-- Datum setzen
set fuTmp to the current date
set AppleScript's text item delimiters to {"."}
set the year of fuTmp to (text item 3 of return_value)
set the month of fuTmp to text item 2 of return_value
set the day of fuTmp to text item 1 of return_value
set theDate to fuTmp
set date of theRecord to theDate
end if
set AppleScript's text item delimiters to oldDelims
end if
end repeat
end tell
end performSmartRule
Aufgerufen werden soll das Script über eine intelligente Regel. Beim Ausführen der Regel erhalte ich nach
set the open_target_file to open for access file target_file with write permission
on performSmartRule (Falsche Zugriffsrechte auf die Datei.)
Kann mir jemand einen Tip geben, wie ich eine temporäre Datei anlegen kann?
Grüße Detlev