On 13/03/2013, at 4:01 PM, Brian Christmas <email@hidden> wrote:
set posixPath to POSIX path of ((holding_folder_temp as text) as alias) set theTempList to my urlsInFolder_(posixPath) <snip>
OK...
tell application "Finder" if the name of holding_folder_temp = "Links" then set parent_Folder to container of holding_folder_temp set t to ((every file of parent_Folder whose name extension = "indd") as alias list) # altered if (count of t) > 0 then set theTempList to {} end if end tell
So I don't understand why you need every .indd file in t, but whatever. You don't get whose clauses, so you have to iterate:
set holdingFolderURL to current application's NSURL's fileURLWithPath_(posixPath) if holdingFolderURL's lastPathComponent() as string = "Links" then set parentURL to holdingFolderURL's URLByDeletingLastPathComponent() set t to {} set tAll to urlsInURL_(theURL) repeat with oneURL in tAll if oneURL's pathExtension() as text = "indd" then set end of t to oneURL -- probably an "exit repeat" would make sense here end if end repeat if (count of t) > 0 then set theTempList to {} end if
repeat with theFile in theTempList try try set oneFile to theFile's getPathComponent() # Doesn't work. on error errmsg display dialog "oneFile 3 " & errmsg end try 1 tell application "Finder" set {creator type:CT, name extension:NE, kind:KI, name:NA} to oneFile if (NE is missing value or NE = "") then if CT = "InDn" then try set name of oneFile to (NA & ".indd") end try end if if CT = "XPR3" then try set name of oneFile to (NA & ".qxp") end try end if if KI = "Rich Text Format (RTF)" then try set name of oneFile to (NA & ".rtf") end try end if if KI = "RTF with attachments (RTFD)" then try set name of oneFile to (NA & ".rtfd") end try end if if KI = "Unix Executable File" then try set name of oneFile to (NA & ".eps") end try end if end if end tell on error errmsg display dialog "Att print 3 " & errmsg end try end repeat
I don't know where you got getPathComponent() from, but I wrote lastPathComponent(). I suspect, however, that what you're really after is pathExtension(). But things get a bit icky with creator type; it's been deprecated since 10.6, and getting it involves as NSFileManager, and dealing with creator types as numbers. Frankly, I suspect by now it's a pointless exercise. However (and this is untested, but should get you close)...
set fileManager to current application's NSFileManager's defaultManager() -- probably redundant at this stage repeat with oneURL in theTempList -- list of URLs set theExt to oneURL's pathExtension() as text if theExt = "" then -- no extension set {theFlag, theValue} to oneURL's getResourceValue_forKey_error_(reference, current application's NSURLLocalizedTypeDescriptionKey, missing value) -- get description set theValue to theValue as text -- coerce to text if theValue = "Rich Text Format (RTF)" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("rtf"), missing value) else if theValue = "RTF with attachments (RTFD)" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("rtfd"), missing value) else if theValue = "Unix Executable File" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("eps"), missing value) else -- fall back to creator type set attRecord to (fileManager's attributesOfItemAtPath_error_(oneURL's |path|(), 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_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("indd"), missing value) else if creatorType = 1.481658931E+9 then -- XPR3 as an integer tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("qxp"), missing value) end if end if end if end repeat
set OnlyPrintIndandQuarkflag to false tell application "Finder" set TempList to (get every file of holding_folder_temp) as alias list # altered repeat with oneFile in TempList try if name extension of oneFile is in {"indd", "inx", "qxp", "qxd"} then set OnlyPrintIndandQuarkflag to true exit repeat end if end try end repeat end tell
I don't understand this. It looks like you're listing the folder again, and then looking for any file with one of those extensions. Why not do the check when you were looping through them all in the first place? So the above would instead be:
set fileManager to current application's NSFileManager's defaultManager() -- probably redundant at this stage set OnlyPrintIndandQuarkflag to false repeat with oneURL in theTempList -- list of URLs set theExt to oneURL's pathExtension() as text if theExt = "" then -- no extension set {theFlag, theValue} to oneURL's getResourceValue_forKey_error_(reference, current application's NSURLLocalizedTypeDescriptionKey, missing value) -- get description set theValue to theValue as text -- coerce to text if theValue = "Rich Text Format (RTF)" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("rtf"), missing value) else if theValue = "RTF with attachments (RTFD)" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("rtfd"), missing value) else if theValue = "Unix Executable File" then tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("eps"), missing value) else -- fall back to creator type set attRecord to (fileManager's attributesOfItemAtPath_error_(oneURL's |path|(), 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_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("indd"), missing value) set OnlyPrintIndandQuarkflag to true else if creatorType = 1.481658931E+9 then -- XPR3 as an integer tell fileManager to moveItemAtURL_toURL_error_(oneURL, oneURL's URLByAppendingPathExtension_("qxp"), missing value) set OnlyPrintIndandQuarkflag to true end if end if else -- it has an extension if theExt is in {"indd", "inx", "qxp", "qxd"} then set OnlyPrintIndandQuarkflag to true end if end if end repeat
|