Author Topic: Moving IDML files into a subfolder  (Read 995 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Moving IDML files into a subfolder
« on: June 11, 2015, 10:10:27 AM »
Good morning. I have an applescript for InDesign CC that I'm working on. It creates an IDML file and moves it into a subfolder named IDML. It also creates the subfolder named IDML if that folder doesn't yet exist. I am getting an error whenever the finder tries to move the IDML files into the IDML subfolder only if that folder already exists.

I assume it has something to do with this line
Code: [Select]
set subFolder to (folder "IDML" of folder parentFolder)
because if I comment out that line and delete the IDML subfolder, it works perfectly.  (If I comment out that line and don't delete the IDML subfolder, then it doesn't run the section of code in the if block that sets the subfolder to make a new folder with properties {name:"IDML"}) and I get an error telling me the variable subFolder is not defined).

So, could someone enlighten me on how I could write it so that it does set the variable subfolder to the correct folder? The full code is below. The interesting thing is I have very similar code that I use to create pdf files from quark and move them into a subfolder and it works great. The part that tells the finder to create the folder and move the files is identical to what is in that script.

Code: [Select]
on open of droppedfiles
tell application "Adobe InDesign CC 2014" to activate
repeat with afile in droppedfiles


--TELLING INDESIGN TO CREATE THE IDML FILE
tell application "Adobe InDesign CC 2014"
open afile
set doc_path to the file path of active document
set doc_name to get name of active document as string
set idml_name to text 1 thru -6 of doc_name
set idml_destination to (doc_path as string) & idml_name & ".idml"
tell active document
export format InDesign markup to idml_destination
close afile saving no
end tell
end tell

--CREATING IDML FOLDER IF IT DOESN'T EXIST YET
set parentFolder to my getParentFolder(afile)
set newFolder to (parentFolder as text) & ":"
if not my CheckForFolder(parentFolder & "IDML:") then
tell application "Finder"
set subFolder to (make new folder at folder parentFolder with properties {name:"IDML"})
end tell
end if
end repeat


--MOVING IDML FILES INTO THE IDML FOLDER
tell application "Finder"
set subFolder to (folder "IDML" of folder parentFolder)
move (files of folder parentFolder whose name extension is "idml") to subFolder with replacing
end tell
end open

--SOME FUNCTIONS FROM A FORUM THAT ARE NEEDED TO MAKE CREATING THE IDML FOLDER WORK
on getParentFolder(filePath)
set folderParts to my GetTextItem(filePath as text, ":", {1, -2})
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set parentFolder to folderParts as text
set AppleScript's text item delimiters to OldDelims

return (parentFolder & ":") as text
end getParentFolder

on CheckForFolder(thisFolder)
tell application "Finder"
return (exists folder thisFolder)
end tell
end CheckForFolder

on GetTextItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
set arrItem to every text item of ThisString


if class of ThisItem is list then
set FromItem to item 1 of ThisItem
set ToItem to item 2 of ThisItem
set TheReturn to (items FromItem thru ToItem of arrItem) as text
else
if ThisItem ≠ 0 then
set TheReturn to (item ThisItem of arrItem) as text
else
set TheReturn to arrItem -- return every items
end if
end if
set the text item delimiters to OldDelims
return TheReturn
end GetTextItem

This is the error I get:
Quote
Can’t get «class cfol» "nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:3_Signs:7x33 Softlines Signs:InDesign Files:*Lifestyle :" of application "Finder".

Thanks!  :)
« Last Edit: June 11, 2015, 11:32:39 AM by mbornbach »

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Moving IDML files into a subfolder
« Reply #1 on: June 11, 2015, 10:44:42 AM »
If it helps, this is the applescript I was referring to for creating pdfs from quark and moving them into a subfolder. This script works like it should.

Code: [Select]
on open of droppedfiles
tell application "QuarkXPress" to activate
repeat with afile in droppedfiles

--TELLING QUARK TO CREATE PDF FILES
tell application "QuarkXPress"
open afile
set my_destination to file path of document 1 as string
set doc_name to get (characters 1 thru -5) of my_destination as string
export document 1 in (doc_name & ".pdf") as "PDF" page range "1, 2" PDF output style "Quad PDF"
close document 1 saving no

--CREATING PDFs FOLDER IF IT DOESN'T EXIST YET
set parentFolder to my getParentFolder(afile)
set newFolder to (parentFolder as text) & ":"
if not my CheckForFolder(parentFolder & "PDFs:") then
tell application "Finder"
set subFolder to (make new folder at folder parentFolder with properties {name:"PDFs"})
end tell
end if
end tell
end repeat

--MOVING PDF FILES INTO THE PDFs FOLDER
tell application "Finder"
set subFolder to (folder "PDFs" of folder parentFolder)
move (files of folder parentFolder whose name extension is "pdf") to subFolder with replacing
end tell
end open

on getParentFolder(filePath)
set folderParts to my GetTextItem(filePath as text, ":", {1, -2})
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set parentFolder to folderParts as text
set AppleScript's text item delimiters to OldDelims

return (parentFolder & ":") as text
end getParentFolder

on CheckForFolder(thisFolder)
tell application "Finder"
return (exists folder thisFolder)
end tell
end CheckForFolder

on GetTextItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
set arrItem to every text item of ThisString


if class of ThisItem is list then
set FromItem to item 1 of ThisItem
set ToItem to item 2 of ThisItem
set TheReturn to (items FromItem thru ToItem of arrItem) as text
else
if ThisItem ≠ 0 then
set TheReturn to (item ThisItem of arrItem) as text
else
set TheReturn to arrItem -- return every items
end if
end if
set the text item delimiters to OldDelims
return TheReturn
end GetTextItem
« Last Edit: June 11, 2015, 11:13:17 AM by mbornbach »

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Moving IDML files into a subfolder
« Reply #2 on: June 12, 2015, 10:47:59 AM »
I was looking for something else and stumbled upon some code that gave me an idea. I have it working now with the following code:

Code: [Select]
on open of droppedfiles
tell application "Adobe InDesign CC 2014" to activate
repeat with afile in droppedfiles


--TELLING INDESIGN TO CREATE THE IDML FILE
tell application "Adobe InDesign CC 2014"
open afile
set doc_path to the file path of active document
set doc_name to get name of active document as string
set idml_name to text 1 thru -6 of doc_name
set idml_destination to (doc_path as string) & idml_name & ".idml"
tell active document
export format InDesign markup to idml_destination
close afile saving no
end tell
end tell

--CREATING IDML FOLDER IF IT DOESN'T EXIST YET
set parentFolder to my getParentFolder(afile)
set newFolder to (parentFolder as text) & ":"
set parentFolder_IDML to parentFolder & "IDML"
if not my CheckForFolder(parentFolder & "IDML:") then
tell application "Finder"
set subFolder to (make new folder at folder parentFolder with properties {name:"IDML"})
end tell
end if
end repeat


--MOVING IDML FILES INTO THE IDML FOLDER
tell application "Finder"
move (files of folder parentFolder whose name extension is "idml") to folder parentFolder_IDML with replacing
end tell
end open

--SOME FUNCTIONS FROM A FORUM THAT ARE NEEDED TO MAKE CREATING THE IDML FOLDER WORK
on getParentFolder(filePath)
set folderParts to my GetTextItem(filePath as text, ":", {1, -2})
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set parentFolder to folderParts as text
set AppleScript's text item delimiters to OldDelims

return (parentFolder & ":") as text
end getParentFolder

on CheckForFolder(thisFolder)
tell application "Finder"
return (exists folder thisFolder)
end tell
end CheckForFolder

on GetTextItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
set arrItem to every text item of ThisString


if class of ThisItem is list then
set FromItem to item 1 of ThisItem
set ToItem to item 2 of ThisItem
set TheReturn to (items FromItem thru ToItem of arrItem) as text
else
if ThisItem ≠ 0 then
set TheReturn to (item ThisItem of arrItem) as text
else
set TheReturn to arrItem -- return every items
end if
end if
set the text item delimiters to OldDelims
return TheReturn
end GetTextItem