I’d appreciate anyone (I guess I’m really asking Shane), to cast their eye over my code, and advise if it’s OK or not.
--
-- AppDelegate.applescript
-- temp
--
-- Created by Brian Christmas on 24/01/2016.
-- Copyright © 2016 MeSelf Software. All rights reserved.
--
script AppDelegate
property parent : class "NSObject"
property holdingFolder : path to desktop
property onlyPrintIndandQuarkflag : false
property ignoreGraphicConverterCount : false
property printGraphicConverterCount : 0
property runForOz : true
-- IBOutlets
property theWindow : missing value
on applicationWillFinishLaunching:aNotification
-- Insert code here to initialize your application before any files are opened
set posixPath to POSIX path of my holdingFolder
my attachmentsPreparationOne()
end applicationWillFinishLaunching:
on attachmentsPreparationOne()
try
say "running"
set p to 1
set my ignoreGraphicConverterCount to false
set my printGraphicConverterCount to 0
set posixPath to POSIX path of (my holdingFolder)
set p to 2
set theTempList to {}
tell application "System Events"
set theItemList to every item of my holdingFolder as list
repeat with eachfile in theItemList
-- Convert input file/folder to a "System Events" alias...
try
set a to eachfile as alias
-- and determine the value of the "URL" property, which is the file URL.
set thisUrl to URL of a
-- Add the file URL to the overall result.
set end of theTempList to thisUrl
end try
end repeat
end tell
set p to 3
set holdingFolderURL to current application's NSURL's fileURLWithPath:(posixPath)
set p to 3.1
if holdingFolderURL's lastPathComponent() as string = "Links" then
set p to 4
set parentURL to holdingFolderURL's URLByDeletingLastPathComponent()
set t to {}
set p to 5
set tAll to urlsInURL_(parentURL)
set p to 6
repeat with oneURL in tAll
if oneURL's pathExtension() as text = "indd" then
set end of t to oneURL
exit repeat
end if
end repeat
if (count of t) > 0 then set theTempList to {}
end if
on error
if my runForOz then say "Prep 1. p = " & p as text
set theTempList to {}
end try
try
set p to 7
set fileManager to current application's NSFileManager's defaultManager() -- probably redundant at this stage
set my onlyPrintIndandQuarkflag to false
set p to 8
set x to 0
repeat with oneURL in theTempList -- list of URLs
set p to 9
set oneURLString to (current application's NSString's stringWithString:(oneURL))
set p to 9.1
set theExt to oneURLString's pathExtension() as text
set p to 10
if theExt = "" then -- no extension
try
set x to x + 1
say x
set p to 11
set {theFlag, theValue} to (oneURL's getResourceValue:(reference) forKey:(current application's NSURLLocalizedTypeDescriptionKey) |error|:(missing value)) -- get description
set p to 12
set theValue to theValue as text -- coerce to text
set p to 13
if theValue = "Rich Text Format (RTF)" then
tell fileManager to moveItemAtURL:(oneURL) toURL:(oneURL's URLByAppendingPathExtension:"rtf") |error|:(missing value)
else if theValue = "RTF with attachments (RTFD)" then
tell fileManager to moveItemAtURL:oneURL toURL:(oneURL's URLByAppendingPathExtension:"rtfd") |error|:(missing value)
else if theValue = "Unix Executable File" then
tell fileManager to moveItemAtURL:oneURL toURL:(oneURL's URLByAppendingPathExtension:"eps") |error|:(missing value)
else -- fall back to creator type
set attRecord to (fileManager's attributesOfItemAtPath:(oneURL's |path|()) |error|:(missing value)) as record -- returns a whole lot of stuff
set creatorType to NSFileHFSCreatorCode of attRecord -- returned as an integer; note pipes around path
if creatorType = 1.231963246E+9 then -- InDn as an integer
tell fileManager to moveItemAtURL:(oneURL) toURL:(oneURL's URLByAppendingPathExtension:"indd") |error|:(missing value)
set my onlyPrintIndandQuarkflag to true
else if creatorType = 1.481658931E+9 then -- XPR3 as an integer
tell fileManager to moveItemAtURL:(oneURL) toURL:(oneURL's URLByAppendingPathExtension:"qxp") |error|:(missing value)
set my onlyPrintIndandQuarkflag to true
end if
end if
end try
else -- it has an extension
if theExt is in {"indd", "inx", "qxp", "qxd"} then
set my onlyPrintIndandQuarkflag to true
end if
end if
end repeat
on error errmsg number errnum
if my runForOz then say "Prep 2. p = " & p as text
if errnum ≠ -1728 and my runForOz then tell application "System Events" to display dialog "attachmentsPreparationOne error " & errmsg & " number " & errnum giving up after 40
end try
#my attachmentsPrintCycleOneInstallFonts() # as alias
end attachmentsPreparationOne
on applicationShouldTerminate:sender
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate:
end script