Monday, December 18, 2017

#1 2017-07-28 02:19:30 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Make Document with copied file name?????

Hey guys ok here it is, I have a script which opens a IMDL file in indesign. Indesign opens these files as "Untitled" new documents. the rest of the script makes a brand new document then i want to save it with the name of the original IMDL name. But somethings wrong, the 'name' isnt being captured.

Any help will make my life easier!

-------------------------- CODE------------------------

Applescript:


tell application "Adobe InDesign CC 2015"
   (*set JobDestination to choose folder with prompt " Choose Destination Folder"*)
   
   --------------open imdl---------------
   set imdlFile to choose file with prompt "Open IMDL File"
   open imdlFile
   
   (*    copy the name of active document to {JobName}*)
   
   ----------------Doc Set up----------------
   set myDocument to make document
   
   tell view preferences of myDocument
       set show frame edges to false
       set vertical measurement units to inches
       set horizontal measurement units to inches
   end tell
   tell document preferences of myDocument
       set page width to 8.5
       set page height to 11
       set facing pages to true
       set page orientation to portrait
       set document bleed top offset to 0
       set document bleed uniform size to true
   end tell
   tell margin preferences
       set top to 0.25
       set left to 0.25
       set bottom to 0.25
       set right to 0.25
   end tell
   
   tell active document
       
       ----------------Make layers----------------    
       set SubLayer to make layer with properties {name:"Sublayer"}
       set BackgroundLayer to make layer with properties {name:"Background"}
       set EditableLayer to make layer with properties {name:"Editable"}
       
       tell layer 4
           delete
       end tell
       
       -------------- Make second page----------------
       make page at after page 1
       set active layer to layer "Background"

       -----save file---------
       (*    save to JobDestination & JobName *)
       save
       
       
   end tell
   
end tell

-----------------------------------------


Filed under: INDD, IMDL, copy filename

Offline

 

#2 2017-07-28 05:28:12 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 772

Re: Make Document with copied file name?????

Hi. You coerced JobName to a list, when you placed it in brackets; nix those. You only use the imdlFile variable once, so I would avoid variabilizing it. If all you need is a name that you're making a new file from, you probably don't even need to open it.

Offline

 

#3 2017-07-31 01:07:35 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

Marc Anthony wrote:

Hi. You coerced JobName to a list, when you placed it in brackets; nix those. You only use the imdlFile variable once, so I would avoid variabilizing it. If all you need is a name that you're making a new file from, you probably don't even need to open it.




THANKS,

unfortunately, i got an error.

"dobe InDesign CC 2015 got an error: Can’t get name of alias "Bedrock:FoxOmni Product:Templates:MN - Templates:22265-CaydenGlen-Landmark-PS-MN:Original:22265-CaydenGlen-Landmark-PS-MN.idml"."

Offline

 

#4 2017-07-31 01:17:37 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

the code was changed to be:

Applescript:


tell application "Adobe InDesign CC 2015"
   
   set JobDestination to choose folder with prompt " Choose Destination Folder"
   
   --------------open imdl---------------
   
   
   set imdlFile to choose file with prompt "Open IMDL File"
   open imdlFile
   
   
   
   copy the name of imdlFile to JobName
   
   ----------------Doc Set up----------------
   set myDocument to make document
   
   tell view preferences of myDocument
       set show frame edges to false
       set vertical measurement units to inches
       set horizontal measurement units to inches
   end tell
   tell document preferences of myDocument
       set page width to 8.5
       set page height to 11
       set facing pages to true
       set page orientation to portrait
       set document bleed top offset to 0
       set document bleed uniform size to true
   end tell
   tell margin preferences
       set top to 0.25
       set left to 0.25
       set bottom to 0.25
       set right to 0.25
   end tell
   
   tell active document
       
       ----------------Make layers----------------    
       set SubLayer to make layer with properties {name:"Sublayer"}
       set BackgroundLayer to make layer with properties {name:"Background"}
       set EditableLayer to make layer with properties {name:"Editable"}
       tell layer 4
           delete
       end tell
       set active layer to layer "Background"
       
       
       
       
       
       -----save file---------
       save to JobDestination & JobName
       
       
   end tell
   
end tell

not sure where i went wrong.....

Offline

 

#5 2017-07-31 01:53:33 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Make Document with copied file name?????

As far as I know, inDesign is unable to extract the name of a file from its pathname.

You may try :

Applescript:


# Two instructions which have no reason to be in the tell Indesign block
   set JobDestination to choose folder with prompt " Choose Destination Folder"
   
set imdlFile to choose file with prompt "Open IMDL File"

# Ask the Finder to extract the name and the name extension
tell application "Finder"
   set JobName to name of imdlFile
   set theExt to name extension of imdlFile
end tell
if theExt is not "" then
# drop the name extension
   set JobName to text 1 thru -(2 + (count theExt)) of JobName
end if

tell application "Adobe InDesign CC 2015"
   
   open imdlFile
   
   
   
   --copy the name of imdlFile to JobName
   
   ----------------Doc Set up----------------
   set myDocument to make document
   
   tell view preferences of myDocument
       set show frame edges to false
       set vertical measurement units to inches
       set horizontal measurement units to inches
   end tell
   tell document preferences of myDocument
       set page width to 8.5
       set page height to 11
       set facing pages to true
       set page orientation to portrait
       set document bleed top offset to 0
       set document bleed uniform size to true
   end tell
   tell margin preferences
       set top to 0.25
       set left to 0.25
       set bottom to 0.25
       set right to 0.25
   end tell
   
   tell active document
       
       ----------------Make layers----------------    
       set SubLayer to make layer with properties {name:"Sublayer"}
       set BackgroundLayer to make layer with properties {name:"Background"}
       set EditableLayer to make layer with properties {name:"Editable"}
       tell layer 4
           delete
       end tell
       set active layer to layer "Background"
       
       
       
       
       
       -----save file---------
       save to JobDestination & JobName
       
       
   end tell
   
end tell

You may also execute this script :

Applescript:


set imdlFile to choose file with prompt "Open IMDL File"

tell application "Adobe InDesign CC 2015"
   
   open imdlFile
   set docName to name of document 1
end tell

Maybe it will give you the wanted name.


Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) lundi 31 juillet 2017 20:44:07

Offline

 

#6 2017-07-31 02:12:12 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 772

Re: Make Document with copied file name?????

Yvan is correct; InDesign has no idea what an alias' name is, but Finder does, so you could avoid opening the document altogether by using it to get the name. Using the opening scheme, you would direct the name command to the resultant document. An alias is not text and can't be concatenated, so you 'll also need to modify the save.


Applescript:

tell application ...
   --------------open imdl---------------
   set JobName to (open my (choose file))'s name --target is opened file, not alias; no need for imdlFile variable
...
       save to (JobDestination as text) & JobName
end

edit: added "my" to avoid silent error from the standard addition command

Last edited by Marc Anthony (2017-07-31 03:15:06 pm)

Offline

 

#7 2017-07-31 02:20:04 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

thanks guys ill try that and tell you how i make out!

Offline

 

#8 2017-07-31 04:36:28 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

Ok Here is the modified script.... But at the end it gets stuck.

Applescript:


set imdlFile to choose file with prompt "Open IMDL File"
set JobDestination to choose folder with prompt " Choose Destination Folder"

# Ask the Finder to extract the name and the name extension

tell application "Finder"
   set JobName to name of imdlFile
   set theExt to name extension of imdlFile
end tell

if theExt is not "" then
   # drop the name extension
   set JobName to text 1 thru -(2 + (count theExt)) of JobName
end if

tell application "Adobe InDesign CC 2015"
   
   open imdlFile
   
   ----------------Doc Set up----------------
   set myDocument to make document with properties {name:JobName}
   
   tell view preferences of myDocument
       set show frame edges to false
       set vertical measurement units to inches
       set horizontal measurement units to inches
   end tell
   tell document preferences of myDocument
       set page width to 8.5
       set page height to 11
       set facing pages to true
       set page orientation to portrait
       set document bleed top offset to 0
       set document bleed uniform size to true
   end tell
   tell margin preferences
       set top to 0.25
       set left to 0.25
       set bottom to 0.25
       set right to 0.25
   end tell
   
   tell active document
       
       ----------------Make layers----------------    
       set SubLayer to make layer with properties {name:"Sublayer"}
       set BackgroundLayer to make layer with properties {name:"Background"}
       set EditableLayer to make layer with properties {name:"Editable"}
       tell layer 4
           delete
       end tell
       set active layer to layer "Background"
       
       
       
       -----save file---------
       save to JobDestination & JobName & "-okThisSucks"
       
   end tell
   
end tell

this
        -----save file---------
        save to JobDestination & JobName & "-okThisSucks"

doesnt work. What are your thoughts?

Offline

 

#9 2017-07-31 05:09:53 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 772

Re: Make Document with copied file name?????

That problem was already addressed in post #6.

Offline

 

#10 2017-07-31 05:52:49 pm

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

Hey I do appreciate your help thank you. Here is the modified script, unfortunately it doesnt like the "name" in the script:
set JobName to (open my (choose file with prompt "Open IMDL File"))'s name
Error: "No result was returned from some part of this expression." number -2763


2. Does these things need to be wrapped in a application Finder tell?
set JobDestination to choose folder with prompt " Choose Destination Folder"
set JobName to (open my (choose file with prompt "Open IMDL File"))'s name


Applescript:



set JobDestination to choose folder with prompt " Choose Destination Folder"
set JobName to (open my (choose file with prompt "Open IMDL File"))'s name


tell application "Adobe InDesign CC 2015"
   
   --------------open imdl---------------
   open imdlFile
   
   ----------------Doc Set up----------------
   set myDocument to make document with properties {name:JobName}
   
   tell view preferences of myDocument
       set show frame edges to false
       set vertical measurement units to inches
       set horizontal measurement units to inches
   end tell
   tell document preferences of myDocument
       set page width to 8.5
       set page height to 11
       set facing pages to true
       set page orientation to portrait
       set document bleed top offset to 0
       set document bleed uniform size to true
   end tell
   tell margin preferences
       set top to 0.25
       set left to 0.25
       set bottom to 0.25
       set right to 0.25
   end tell
   
   tell active document
       
       ----------------Make layers----------------    
       set SubLayer to make layer with properties {name:"Sublayer"}
       set BackgroundLayer to make layer with properties {name:"Background"}
       set EditableLayer to make layer with properties {name:"Editable"}
       tell layer 4
           delete
       end tell
       set active layer to layer "Background"
       
       
       
       -----save file---------
       
       save to JobDestination & JobName

       
   end tell
   
end tell

Offline

 

#11 2017-08-01 04:52:32 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Make Document with copied file name?????

Marc Anthony gave the explanation and the solution in message #6.
You just need to read carefully.

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mardi 1 aout 2017 11:52:11

Offline

 

#12 2017-08-01 11:13:02 am

scottmemberg
Member
Registered: 2014-03-25
Posts: 15

Re: Make Document with copied file name?????

Yvan Koenig wrote:

Marc Anthony gave the explanation and the solution in message #6.
You just need to read carefully.

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mardi 1 aout 2017 11:52:11



``````I do hope you are not a teacher. This comment was not helpful. I am NOT a coder. I can read just find my friend.

"Using the opening scheme, you would direct the name command to the resultant document." this means nothing to me, since I do not know what it is in reference to. I like to teach by example. I have pieced this whole script together from bits of scripts i have learned over the last year.

I have put the entire script here not to be picked apart but to show as a reference to what is going on. Both of you fine gentlemen gave some nice imput but didn't bother to just re-insert into the whole script to show where it would fit in the " Scheme of things"

Im sure there were a lot of assumptions on your part and that's natural, you don't have to talk down to me.

The problem I am having is that applescript doesnt get me the "name" of a file which, when opened has no name. So I understand that I might be able to get the name from the "FINDER", set that as a variable or string? then use it at the end of the script when the document that was created needs to be saved.

The process which I wanted to achieve is as follows:

1. Set a destination folder. (when time to save the final doc can be placed)
2. Get the name of a IMDL file, so i don't have to type into a dialog box when saving
3. Create a new document using that name of the IMDL file (NOT including the extension)
4. Open the IMDL file.

Thanks!

Offline

 

#13 2017-08-01 12:10:35 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Make Document with copied file name?????

The problem is not that I am not a teacher. It is that you didn't read carefully.



In message #6, Marc Anthony carefullly urged you to write :
set JobName to (open my (choose file))'s name
## rest of the code
save to (JobDestination as text) & JobName

In message #8 you wrote that :
set JobName to (open my (choose file))'s name
## rest of the code
save to JobDestination & JobName & "-okThisSucks"
was failing.

In message #9, Marc Anthony gently wrote :
That problem was already addressed in post #6.

In message #10 you wrote that :
set JobName to (open my (choose file))'s name
## rest of the code
save to JobDestination & JobName
was failing.

In message #11 I politely wrote :
Marc Anthony gave the explanation and the solution in message #6.
You just need to read carefully.


In message #12 it was clear that you didn't read carefully.

Here, I try to help you one more time. You wrote:

set JobName to (open my (choose file))'s name
## rest of the code
save to JobDestination & JobName

To help you to compare, I reproduce here what Marc wrote :
save to (JobDestination as text) & JobName
The difference with your wording is clear, isn't it ?

More, Marc wrote also :
Using the opening scheme, you would direct the name command to the resultant document.
You took care of that but you clearly missed the second sentence.
An alias is not text and can't be concatenated, so you 'll also need to modify the save.

It's true that I am not a teacher but I'm sure that it's not what is the meaningful point here.

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mardi 1 aout 2017 19:10:29

Last edited by Yvan Koenig (2017-08-01 12:12:41 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)