Push-Nachrichten von MacTechNews.de
Würden Sie gerne aktuelle Nachrichten aus der Apple-Welt direkt über Push-Nachrichten erhalten?
Forum>Software>Fehler in Applescript

Fehler in Applescript

A-Ha28.12.0920:47
Hallo zusammen
Ich benötige ein Applescript für eine Ordneraktion, um Chemdraw-Dateien als tiff-Dateien zu sichern. Dazu findet sich im Internet auch ein Skript. So weit, so gut. Allerdings funktioniert dieses Skript bei mir (Mac OS X 10.4.11 und Max OS X 10.5.7) nicht. Ich habe schon etwas Nachforschungen angestellt und eine funktionsfähige Variante zusammengebastelt, die ihren Dienst mit einer Einzeldatei tut, nicht aber als Ordneraktion.

Das Skript aus dem Internet scheint irgendein Problem mit den Dateipfaden zu haben. Kann mir jemand helfen? Ich selber werde den Fehler wohl kaum finden, dazu habe ich zu wenig Ahnung von Applescript.


Nachfolgend die funktionstüchtige Variante:

*********

tell application "CS ChemDraw Pro"
activate
set source_file to "Users:andreas96:Desktop:vorlage.cdx" as string
set target_path to ((path to desktop folder as string) & "vorlage.tif") as string
open file source_file

save first document in target_path as "TIFF"
close first document
end tell

*********

Und hier das Skript aus dem Internet. Problematisch ist die fett markierte Subroutine:

*********

property done_foldername : "TIFF Images"
property originals_foldername : "Original CD Files"
property newimage_extension : "tiff"
-- the list of file types which will be processed
-- -- eg: {"CDX", "CML"} for chemdraw or chemical markup language
property type_list : {"CDX"}
-- since file types are optional in Mac OS X,
-- check the name extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions list
-- eg: {"cdx}, NOT: {".cdx"}
property extension_list : {"cdx"}


on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder done_foldername of this_folder) then
make new folder at this_folder with properties {name:done_foldername}
end if
set the results_folder to (folder done_foldername of this_folder) as alias
if not (exists folder originals_foldername of this_folder) then
make new folder at this_folder with properties {name:originals_foldername}
set current view of container window of this_folder to list view
end if
set the originals_folder to folder originals_foldername of this_folder
end tell
try
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
tell application "Finder"
my resolve_conflicts(this_item, originals_folder, "")
set the new_name to my resolve_conflicts(this_item, results_folder, newimage_extension)
--set the source_file to (move this_item to the originals_folder with replacing) as alias

set the source_file to (move this_item to the originals_folder with replacing) as text

end tell

process_item(source_file, new_name, results_folder)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end adding folder items to

on resolve_conflicts(this_item, target_folder, new_extension)
tell application "Finder"
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
if the new_extension is "" then
set target_name to file_name
set target_extension to file_extension
else
set target_extension to new_extension
set target_name to (the trimmed_name & "." & target_extension) as string
end if
if (exists document file target_name of target_folder) then
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & "." & (name_increment as string) & "." & target_extension) as string
if not (exists document file new_name of the target_folder) then
-- rename to conflicting file
set the name of document file target_name of the target_folder to the new_name
exit repeat
else
set the name_increment to the name_increment + 1
end if
end repeat
end if
end tell
return the target_name
display dialog target_name
end resolve_conflicts

-- this sub-routine processes files
on process_item(source_file, new_name, results_folder)
-- FILE PROCESSING STATEMENTS GOES HERE
try


-- the target path is the destination folder and the new file name
set the target_path to ((results_folder as string) & new_name) as string
with timeout of 900 seconds

tell application "CS ChemDraw Pro"
activate
display dialog target_path

--display dialog source_file

open file source_file

save first document in target_path as "TIFF"
close first document
end tell


end timeout
on error error_message
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end try
end process_item

*********
0

Kommentare

_mäuschen
_mäuschen29.12.0901:31

Lösche file

in

open file source_file


0
A-Ha29.12.0908:00
Vielen Dank für Deine Mühe, _mäuschen. Ich habe Deinen Vorschlag ausprobiert, leider ohne Erfolg. Das Öffnen der Dateien funktioniert interessanterweise reibungslos, nicht aber das Sichern. Ich sehe den Grund nicht, warum das Skript nicht sichern kann – öffnen und sichern sind ja zwei völlig analoge Befehle. Hat sonst noch jemand eine Idee?

Mittlerweile habe ich weiter rumgebastelt und folgendes funktionsfähigs Skript erhalten, das leider alle neu erzeugten tif-Dateien mit einem neuen, mit einer Nummer versehenen Namen versieht – der alte Name wird gelöscht:


*********

on adding folder items to this_folder after receiving these_items
try
repeat with i from 1 to number of items in these_items
tell application "CS ChemDraw Pro"
activate
set this_item to item i of these_items
set source_file to this_item as string
set target_path to ((path to desktop folder as string) & "cdx in gif konvertieren:konvertiert" & i & ".tif") as string
open file source_file

save first document in target_path as "TIFF"
close first document
end tell
end repeat
end try
end adding folder items to

*********
0
_mäuschen
_mäuschen29.12.0911:05

Eventuell liegt das open file Problem an den unterschiedlichen ChemDraw Versionen.

Für das zweite Problemchen kann ich Dir diese Variante zum Studium anbieten:

0
A-Ha04.01.1017:54
Danke für Deinen Vorschlag, _mäuschen. Dein Skript funktioniert bis zum Öffnen der ausgewählten Datei. Erneut scheitert indes das Sichern der Datei. Sobald ich übrigens "target_path" durch einen konkreten Dateipfad ersetze, läuft das Skript tadellos.
Da kommt mir in den Sinn: Ich habe zwei Versionen von ChemDraw auf meinem Rechner installiert. Wäre es möglich, dass sie sich in die Quere kommen?

0
_mäuschen
_mäuschen05.01.1012:08


Wie oben schon erwähnt, läuft bei mir der script (ob www.macresearch.org oder homepage.mac.com/swain) problemlos,
wenn ich file entferne.

Siehe ChemDraw AppleScript Dictionary open

Siehe auch open OneFile (ohne file)


Für weitere Problemlösungsvorschläge würde ich mich direkt an www.cambridgesoft.com wenden.

P.S. Seminar in Basel


0
A-Ha05.01.1017:05
Hallo _mäuschen. Vielen lieben Dank für Deine Hilfe. Es ist nicht selbstverständlich, dass sich jemand die Mühe macht und sich durch das Riesenskript im Anfangsbeitrag arbeitet.
Nichtsdestotrotz: Das Problem lag definitiv nicht beim Wort "file", sondern daran, dass ich zwei ChemDraw-Versionen nebeneinander installiert hatte (ChemDraw Pro 7 und ChemDraw 9 Std). Ich habe die 7er-Version entfernt, und jetzt läuft das Skript problemlos. Offenbar kommen sich die beiden Versionen skripttechnisch in die Quere.
0
_mäuschen
_mäuschen05.01.1017:09

Ich habe hier die CS ChemDraw Ultra

und die will das file nicht

0
_mäuschen
_mäuschen05.01.1017:43

tell application "CS ChemDraw Ultra"
activate
open file "Leo:Users:Admin:Desktop:Original CD Files:Original CD Files:dimethylamine2.cdx"
error "an unexpected error occurred (#-50)" number -50
end tell

0
_mäuschen
_mäuschen05.01.1017:45

Gegenüber: ohne file

tell application "CS ChemDraw Ultra"
activate
open "Leo:Users:Admin:Desktop:Original CD Files:Original CD Files:dimethylamine2.cdx"
-- > document id 875
save document 1 in "Leo:Users:Admin:Desktop:Original CD Files:TIFF Images:dimethylamine2.tiff" as "TIFF"
close document 1
end tell
0

Kommentieren

Diese Diskussion ist bereits mehr als 3 Monate alt und kann daher nicht mehr kommentiert werden.