It would be easy to edit the script to work with file which have no extension name.
The problem is to find a way to be sure that the passed file is really a crtr one.
I’m not sure of the meaning of what you wrote.
Is the file save with no extension or is it with the extension hidden ?
May you run this script and post the content of the file “myLog2_2goLym.txt” which will be created on the desktop ?
I hope that one of the returned values will give a way to check the nature of the passed file.
set aFile to choose file with prompt "choose a file of type crtr"
set myLog to (path to desktop as text) & "myLog2_2goLym.txt"
my writeto(myLog, "with System Events", text, false)
tell application "System Events" to tell disk item (aFile as text)
set itsName to its name
my writeto(myLog, "itsName = " & itsName, text, true)
set itsDisplayedName to its displayed name
my writeto(myLog, "itsDisplayedName = " & itsDisplayedName, text, true)
set itsTypeID to its type identifier
my writeto(myLog, "itsTypeId = " & itsTypeID, text, true)
set itsExtension to its name extension
my writeto(myLog, "itsExtension = " & itsExtension, text, true)
set itsKind to its kind
my writeto(myLog, "itsKind = " & itsKind, text, true)
end tell
my writeto(myLog, "with Finder", text, true)
tell application "Finder"
set itsName to name of aFile
my writeto(myLog, "itsName = " & itsName, text, true)
set itsDisplayedName to displayed name of aFile
my writeto(myLog, "itsDisplayedName = " & itsDisplayedName, text, true)
set itsExtension to name extension of aFile
my writeto(myLog, "itsExtension = " & itsExtension, text, true)
set itsKind to kind of aFile
my writeto(myLog, "itsKind = " & itsKind, text, true)
set itsExtensionHidden to extension hidden of aFile
my writeto(myLog, "itsExtensionHidden = " & itsExtensionHidden, text, true)
end tell
Here is a temporary version of the “main” script.
It is supposed to be able to treat files with the extension as well as files without it.
set myLog to (path to desktop as text) & "myLog_goLym.txt"
set aFile to choose file with prompt "Choose a "crtr" file."
set {name:fileName, name extension:fileExtension} to info for aFile
my writeto(myLog, "fileName = " & fileName & linefeed & "fileExtension = " & fileExtension & linefeed, text, false)
if fileExtension = "crtr" then
if (count fileName) > 12 then
set baseName to text -12 thru -6 of fileName
my writeto(myLog, "point 1" & linefeed, text, true)
else
set baseName to text 1 thru -6 of fileName
my writeto(myLog, "point 2" & linefeed, text, true)
end if
else if fileExtension is missing value then
set baseName to text -7 thru -1 of fileName
else
error "wrong kind of file"
end if
my writeto(myLog, "baseName = " & baseName & linefeed, text, true)
set PDFPath to "mymountedVolume:"
tell application "MultiAd Creator Pro"
activate
--try
# aFile is an alias so there is no need to explicitely define the class
--open (aFile as alias)
my writeto(myLog, "point 3" & linefeed, text, true)
open aFile
my writeto(myLog, "point 4" & linefeed, text, true)
set theDoc to document 1
my writeto(myLog, "point 5" & linefeed, text, true)
set destFolder to PDFPath
my writeto(myLog, "point 6" & linefeed, text, true)
# Assuming that the filename match the original asker description,
# you are trying to export into : "mymountedVolume:1234567:myfilename1234567.crtr.pdf"
# Is it really what you want.
my writeto(myLog, "point 7, want to save in :" & linefeed & (destFolder & baseName & ".pdf") & linefeed, text, true)
display dialog "want to save in :" & linefeed & (destFolder & baseName & ".pdf")
--tell application "MultiAd Creator Pro" # No need for that, you are already speaking to this application
(*
export PDF current spread of theDoc saving in (destFolder & baseName & ":" & fileName & ".pdf") print order user order export method composite output color space CMYK stand in resolution 300 black and white compression use zip color image compression use JPEG quality 100 with embed no base 14 fonts, use doc size, binary encoding and compress text and line art without print as spreads, crop marks, registration marks, color bars, document notes, plate information, text blocks only and presentation mode
*)
-- end tell
my writeto(myLog, "point 8" & linefeed, text, true)
close front document saving no
my writeto(myLog, "point 9" & linefeed, text, true)
(*
on error e
display dialog "an error occured " & e
end try
*)
end tell
#=====
(*
Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861
*)
on writeto(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as «class furl»
set openFile to open for access targetFile with write permission
if not apendData then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access targetFile
end try
return false
end try
end writeto
#=====
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) jeudi 18 mai 2017 20:44:55