property inputformat : ""

property outputname : ""

 

on existsfile(filename)

try

set temp to size of (info for (alias filename))

on error errmsg number errnum

return false

end try

return true

end existsfile

on ext(filename)

set oldDelims to text item delimiters of AppleScript

set text item delimiters of AppleScript to {"."}

set justextension to last text item of (filename as string)

set text item delimiters of AppleScript to oldDelims

if justextension contains ":" then

set justextension to ""

end if

return justextension

end ext

on thefilename(filename)

set oldDelims to text item delimiters of AppleScript

set text item delimiters of AppleScript to {":"}

set justname to last text item of (filename as string)

set text item delimiters of AppleScript to oldDelims

return justname

end thefilename

on showhelp(helpscreen)

if helpscreen is 1 then

display dialog "This droplet will do batch conversions to and" & return ¬

& "from any format that can be written and read by CS ChemDraw Pro." buttons {"Help", "Quit", "Convert"} default button "Convert"

set answer to button returned of result

if answer is "Help" then

set helpscreen to 2

else if answer is "Quit" then

error number -128

else if answer is "Convert" then

set helpscreen to 3

end if

else if helpscreen is 2 then

display dialog "Maybe I should put some more help here." buttons {"<< Back", "Quit", "Convert"} default button "Convert"

set answer to button returned of result

if answer is "<< Back" then

set helpscreen to 1

else if answer is "Quit" then

error number -128

else if answer is "Convert" then

set helpscreen to 3

end if

else if helpscreen is 3 then

display dialog "Default input format: " & inputformat & return & "Output format: " & outputname buttons {"Set format", "Quit", "Convert"} default button "Convert"

set answer to button returned of result

if answer is "Set format" then

set helpscreen to 4

else if answer is "Quit" then

error number -128

else if answer is "Convert" then

if outputname is "" then

set helpscreen to 5

else

set helpscreen to 99 -- exit help session

end if

end if

else if helpscreen is 4 then

display dialog "Select output format:" & return & return & ¬

"ChemDraw" & return & ¬

"ChemDraw Stationery" & return & ¬

"ChemDraw 2.1" & return & ¬

"ChemDraw 2.0" & return & ¬

"PICT" & return & ¬

"PICT scaled 4x" & return & ¬

"EPS (Mac)" & return & ¬

"EPS (Text)" & return & ¬

"Connection Table" & return & ¬

"MDL MOLfile (Mac)" & return & ¬

"MDL MOLfile (Text)" & return & ¬

"Molecular Simulations Molfile" & return & ¬

¬

"SMD 4.2 File" default answer ¬

outputname buttons {"Set input format", "Quit", "OK"} default button "OK"

set temp to result

set outputname to text returned of temp

set answer to button returned of temp

if answer is "Set input format" then

if outputname is in {"", "ChemDraw", "ChemDraw Stationery", "ChemDraw 2.1", "ChemDraw 2.0", "PICT", "PICT scaled 4x", "EPS (Mac)", "EPS (Text)", "Connection Table", "MDL MOLfile (Mac)", "MDL MOLfile (Text)", "Molecular Simulations Molfile", "SMD 4.2 File"} then

set helpscreen to 6

else

display dialog "Please enter the output format exactly as shown!" buttons {"OK"} default button "OK"

set helpscreen to 4

end if

else if answer is "Quit" then

error number -128

else if answer is "OK" then

if outputname is in {"", "ChemDraw", "ChemDraw Stationery", "ChemDraw 2.1", "ChemDraw 2.0", "PICT", "PICT scaled 4x", "EPS (Mac)", "EPS (Text)", "Connection Table", "MDL MOLfile (Mac)", "MDL MOLfile (Text)", "Molecular Simulations Molfile", "SMD 4.2 File"} then

set helpscreen to 3

else

display dialog "Please enter the output format exactly as shown!" buttons {"OK"} default button "OK"

set helpscreen to 4

end if

end if

else if helpscreen is 5 then

display dialog "Please set the output format!" buttons {"OK"} default button "OK"

set helpscreen to 4

else if helpscreen is 6 then

display dialog "If you leave the default input format blank, ChemDraw will prompt you for each file. Select from:" & return & return & ¬

"Connection Table" & return & ¬

"MDL MOLfile (Mac)" & return & ¬

"MDL MOLfile (Text)" & return & ¬

"Molecular Simulations Molfile" & return & ¬

"SMD 4.2 File" default answer ¬

inputformat buttons {"Set output format", "Quit", "OK"} default button "OK"

set temp to result

set inputformat to text returned of temp

set answer to button returned of temp

if answer is "Set output format" then

if inputformat is in {"", "Connection Table", "MDL MOLfile (Mac)", "MDL MOLfile (Text)", "Molecular Simulations Molfile", "SMD 4.2 File"} then

set helpscreen to 4

else

display dialog "Please enter the input format exactly as shown!" buttons {"OK"} default button "OK"

set helpscreen to 6

end if

else if answer is "Quit" then

error number -128

else if answer is "OK" then

if inputformat is in {"", "Connection Table", "MDL MOLfile (Mac)", "MDL MOLfile (Text)", "Molecular Simulations Molfile", "SMD 4.2 File"} then

set helpscreen to 3

else

display dialog "Please enter the input format exactly as shown!" buttons {"OK"} default button "OK"

set helpscreen to 6

end if

end if

end if

return helpscreen

end showhelp

on open fileList

set helpscreen to 1

repeat while helpscreen < 99

--display dialog "helpscreen: " & helpscreen buttons {"OK"} default button 1

set helpscreen to showhelp(helpscreen) of me

end repeat

repeat with OneFile in fileList

if (folder of (info for OneFile)) is false then

set isgoodfile to true

set creator to file creator of (info for (OneFile))

set type to file type of (info for (OneFile))

set extension to ext(OneFile) of me

tell application "CS ChemDraw Ultra™"

if (((extension is "CHM") or (extension is "chm") or (extension is "skc") or (extension is "tgf")) ¬

or ((creator is "CHMD") ¬

and ((type is "CHMS") ¬

or (type is "PICT") ¬

or (type is "sHMS") ¬

or (type is "EPSF") ¬

or (type is "mSKC") ¬

or (type is "mTGF")))) then

try

open OneFile

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else if errnum = -35 then

open OneFile

else

error "" & (OneFile as string) & return & return & "Unexpected error " & errnum & ": " & errmsg

end if

end try

else if (((extension is "MDL") or (extension is "mdl") or ¬

(extension is "MOL") or (extension is "mol")) ¬

or ((creator is "CHMD") and (type is "mMOL"))) then

try

open OneFile as "MDL MolFile (Mac)"

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else

error "Unexpected error " & errnum & ": " & errmsg

end if

end try

else if ((extension is "MSI") or (extension is "msi")) then

try

open OneFile as "Molecular Simulations Molfile"

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else

error "Unexpected error " & errnum & ": " & errmsg

end if

end try

else if ((extension is "SMD") or (extension is "smd")) then

try

open OneFile as "SMD 4.2 File"

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else

error "Unexpected error " & errnum & ": " & errmsg

end if

end try

else if inputformat is not "" then

try

open OneFile as inputformat

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else

error "Unexpected error " & errnum & ": " & errmsg

end if

end try

else

try

open OneFile

on error errmsg number errnum

if errnum = -10000 then

display dialog "I do not think that that ChemDraw can understand the file " & OneFile as string

set isgoodfile to false

else if errnum = -127 then

else

error "Unexpected error " & errnum & ": " & errmsg

end if

end try

end if

if isgoodfile is true then

if outputname is "ChemDraw" then

set outputformat to "CHMS"

set newext to "chm"

else if outputname is "ChemDraw Stationery" then

set outputformat to "sHMS"

set newext to "chmst"

else if outputname is "ChemDraw 2.1" then

set outputformat to "CH21"

set newext to "chm21"

else if outputname is "ChemDraw 2.0" then

set outputformat to "CH20"

set newext to "chm20"

else if outputname is "PICT" then

set outputformat to "PICT"

set newext to "pict"

else if outputname is "PICT scaled 4x" then

set outputformat to "PIC4"

set newext to "pict4x"

else if outputname is "EPS (Mac)" then

set outputformat to "EPSF"

set newext to "epsmac"

else if outputname is "EPS (Text)" then

set outputformat to "EPST"

set newext to "epstxt"

else if outputname is "SKC" then

set outputformat to "mSKC"

set newext to "SKC"

else if outputname is "TGF" then

set outputformat to "mTGF"

set newext to "TGF"

else if outputname is "Connection Table" then

set outputformat to "TEXT"

set newext to "ct"

else if outputname is "MDL MOLfile (Mac)" then

set outputformat to "mMOL"

set newext to "molmac"

else if outputname is "MDL MOLfile (Text)" then

set outputformat to outputname

set newext to "moltxt"

else if outputname is "Molecular Simulations Molfile" then

set outputformat to outputname

set newext to "msi"

else if outputname is "SMD 4.2 File" then

set outputformat to outputname

set newext to "smd"

end if

if extension is "" then

set newext to "." & newext

end if

set theproposedlength to (length of (thefilename(OneFile) of me)) - (length of extension) + (length of newext)

set OneFile to (OneFile as string) -- won’t need it in any other form from this point

if theproposedlength < 32 then

set OneFile to (characters 1 thru ((length of OneFile) - (length of extension)) of OneFile) & newext

else

if first character of newext is not "." then

set newext to "." & newext

set theproposedlength to theproposedlength + 1

end if

set OneFile to (characters 1 thru ((length of OneFile) - (length of extension) - (theproposedlength - 31)) of OneFile) & newext

end if

set OneFile to (OneFile as string)

repeat while existsfile(OneFile) of me

set badchar to ((length of OneFile) - (length of newext))

if first character of newext is not "." then

set badchar to badchar - 1

end if

set OneFile to (characters 1 thru (badchar - 1) of OneFile) & ¬

(ASCII character ((ASCII number of (character badchar of OneFile)) + 1)) & ¬

(characters (badchar + 1) thru end of OneFile) as string

end repeat

try

save first document in OneFile as outputformat

on error errmsg number errnum

error "" & (OneFile as string) & return & "Format: " & outputformat & return & return & "Unexpected error " & errnum & ": " & errmsg

end try

try

close first document saving no

on error errmsg number errnum

error "Unexpected error " & errnum & ": " & errmsg

end try

end if --isgoodfile

end tell

end if

end repeat

end open



2005 CambridgeSoft Corporation. All Rights Reserved. Privacy Statement
Tel  800 315-7300 / 617 588-9300     Fax  617 588-9390     Email   info@cambridgesoft.com
CambridgeSoft Corporation, 100 CambridgePark Drive, Cambridge, MA 02140 USA