• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Requesting help, please
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Requesting help, please


  • Subject: Re: Requesting help, please
  • From: Brian Christmas <email@hidden>
  • Date: Mon, 25 Jan 2016 13:58:18 +1100

G’day Shane, and thank you!

Regards

Santa


On 25 Jan 2016, at 12:06 PM, Shane Stanley <email@hidden> wrote:

On 24 Jan 2016, at 10:48 PM, Brian Christmas <email@hidden> wrote:

It just seemed self evident to me what the code was trying to do

Honestly, it's not. Using variable names like t and tAll doesn't help. What's x about? Your onlyPrintIndandQuarkflag appears to end up with the value set by the last file, which would appear to make it useless. There's just too much noise that helps make it unreadable.

Here's a handler to get the URLs in the folder:

on getItemsInPOSIXPath:posixPathOfHoldingFolder
set fileManager to current application's NSFileManager's defaultManager()
set holdingFolderURL to current application's class "NSURL"'s fileURLWithPath:(posixPathOfHoldingFolder)
set {theURLs, theErrors} to fileManager's contentsOfDirectoryAtURL:holdingFolderURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
return {theURLs, theErrors} -- theURLs will be missing value if there's an error
end getItemsInPOSIXPath:

And here's you extension-guessing code written as a handler:

on checkURLCanBeProcessed:oneURL
set theExt to oneURLString's pathExtension() as text
if theExt is not "" then
if theExt is in {"indd", "inx", "qxp", "qxd"} then
return {canProcess:true, isQuarkOrInd:true}
else
return {canProcess:true, isQuarkOrInd:false}
end if
end if
set {theFlag, theValue} to (oneURL's getResourceValue:(reference) forKey:(current application's NSURLLocalizedTypeDescriptionKey) |error|:(missing value)) -- get description
if (theFlag as boolean) is false then return {canProcess:false, isQuarkOrInd:false} -- something went wrong getting the resource value
set theValue to theValue as text
set fileManager to current application's NSFileManager's defaultManager()
if theValue = "Rich Text Format (RTF)" then
tell fileManager to moveItemAtURL:(oneURL) toURL:(oneURL's URLByAppendingPathExtension:"rtf") |error|:(missing value)
return {canProcess:true, isQuarkOrInd:false}
else if theValue = "RTF with attachments (RTFD)" then
tell fileManager to moveItemAtURL:oneURL toURL:(oneURL's URLByAppendingPathExtension:"rtfd") |error|:(missing value)
return {canProcess:true, isQuarkOrInd:false}
else if theValue = "Unix Executable File" then
tell fileManager to moveItemAtURL:oneURL toURL:(oneURL's URLByAppendingPathExtension:"eps") |error|:(missing value)
return {canProcess:true, isQuarkOrInd:false}
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
if creatorType = 1.231963246E+9 then -- InDn as an integer
tell fileManager to moveItemAtURL:(oneURL) toURL:(oneURL's URLByAppendingPathExtension:"indd") |error|:(missing value)
return {canProcess:true, isQuarkOrInd: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)
return {canProcess:true, isQuarkOrInd:true}
else -- got nowhere
return {canProcess:false, isQuarkOrInd:false}
end if
end if
end checkURLCanBeProcessed:

Now redo you handler to use them. But don't just try to copy and paste -- rewrite the handler completely, trying to make it simpler and easy to follow. 

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
Do not post admin requests to the list. They will be ignored. applescriptobjc-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Requesting help, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help, please (From: Shane Stanley <email@hidden>)
 >Re: Requesting help, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help, please (From: Shane Stanley <email@hidden>)
 >Re: Requesting help, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help, please (From: Shane Stanley <email@hidden>)
 >Re: Requesting help, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help, please (From: Shane Stanley <email@hidden>)
 >Re: Requesting help, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help, please (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Styled Text
  • Next by Date: Very basic help, please
  • Previous by thread: Re: Requesting help, please
  • Next by thread: Very basic help, please
  • Index(es):
    • Date
    • Thread