I have variable data saved as a string in my script as this_file
In the script, I have just created a file and saved it to a folder on my harddrive.
I would actually like it to be named as the file information stored in this_file
Here is the relevant script…
tell application "Adobe Acrobat 7.0 Pro#DE835"
save document 1 to "Ren Mark G4-5:save:first"
close all docs saving no
end tell
tell application "Finder"
set newest_file to alias "Ren Mark G4-5:save:first"
set this_item to this_item as alias -- currently a string
set newest_file to name of this_item
end tell
This doesn’t work. Ideally, I would like to save the Acrobat file originally with the information stored in this_file. I know the information is there, because when I get an as error on this it displays it.
I am really new at this and trying my butt off. Any help somebody could offer here would be super appreciated.
Why aren’t you just putting the info in this_file directly into the name?
save document 1 to “Ren Mark G4-5:save:” & this_file
etc.
Thank you for the quick reply Adam ![:slight_smile: :slight_smile:](https://www.macscripter.net/images/emoji/apple/slight_smile.png?v=12)
Ok, this_item is set as a string currently with the string being “hard-drive:folder:file name of file being currently worked on in repeating script”.
I’m not quite sure how to get that information into my save command for Acrobat.
I tried both this
tell application "Adobe Acrobat 7.0 Pro#DE835"
save document 1 to "Ren Mark G4-5:save" & this_item
and this
set this_item to this_item as alias
tell application "Adobe Acrobat 7.0 Pro#DE835"
save document 1 to "Ren Mark G4-5:save" & this_item
both times I got an error saying document 1 doesn’t understand save command. Any thoughts? A more complete version of the script is in an unanswered post from Friday if that helps any…
I know it’s simple and I am terribly dense, but I am trying. From square 1 I have a written script that will open a tif in illustrator, detect size of tiff and crop it with variable dimensions, save to pdf…now this script… open pdf, copy, paste into template and now save under the original Illustrator filename with date. This is the LAST part of all that…
Ahh, I didn’t realize that this_item was a complete path: hard-drive:folder:file_name. What you want is the file_name to append, not the path because you want the same name but a new path as I understand it. (Your tries were failing because a name can’t contain a colon, by the way)
tell application "Finder" to set file_name to name of (this_item as alias)
and then use file_name in your save.
Alternatively
set AppleScript's text item delimiters to ":"
set file_name to last text item of this_item
set AppleScript's text item delimiters to ""
file_name
Adam (or whoever else can help)
Day off yesterday and now back to this script… hopefully the thread didn’t get too old for a reply.
I just tried both methods of getting the save path as described above and using this code,
tell application "Adobe Acrobat 7.0 Pro#DE835"
save document 1 to "Ren Mark G4-5:save:" & file_name
I recieved "Acrobat got an error: document 1 doesn’t understand the save message.
Now this has me stumped. I created a viariable for the above save path
set new_path to "Ren Mark G4:save" & file_name
display dialog new_path
The dialog came back as, Ren Mark G4:save:xxx.pdf. If I type that exactly into the save path Acrobat understands and saves fine, but for some reason Acrobat is not understanding it as input through a variable. Hopefully this is comprehensible and somebody has an idea…
I think I figured this out FINALLY
instead of telling acrobat to
save to your_path
like you would
save to "xxx:xxx:xxx"
you need to tell it to
save to filename your_path
How obtuse. Now to figure out how to get the date into the filename…
Something like this? (don’t know whether your file name has an extension)
-- For name with a known extension
to AddDateTo(fileName, delim, ext) -- delim can be "", i.e. nothing
set d to delim
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ext
set fName to first text item of fileName
set AppleScript's text item delimiters to astid
tell (current date) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string ¬
to return fName & text -2 thru -1 & d & text 4 thru 5 & d & text 2 thru 3 & ext
end AddDateTo
AddDateTo("Starlog.pdf", "", ".pdf") --> Starlog060621.pdf
Or if there is no extension then:
to AddDateTo(fileName, delim)
set d to delim
tell (current date) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string ¬
to return fileName & text -2 thru -1 & d & text 4 thru 5 & d & text 2 thru 3
end AddDateTo
AddDateTo("Starlog", "") --> Starlog060621
Thanks for all the help Adam
I was able to insert the date during creation like this
set my_date to short date string of (current date)
set new_path to "Jobs_Vol:COMPLETED PDF:" & my_date & file_name
The entire script works now… for the most part. Color tiff is saved to folder. Illustrator is triggered. Illustrator creates proper sized box and crops tiff. illustrator saves as PDF. Acrobat opens PDF, copies out information and pastes into prettified template. New file is saved into a folder with date.
SLICK… and potentially a huge time saver…
Except for the fact that…
A. Server folders have a TERRIBLE refresh in OSX and the folder action doesn’t trigger reliably.
B. Acrobat has a long standing bug where it crashes during copy and paste.
Maybe an applet would be better???
More than welcome.
Not clear from this thread what the workflow is here. I gather that files are being dropped into a folder on a server by others, you’re grabbing them to do your Illustrator/PDF tricks, and the PDF stays with you or goes back to the server. The script is on your machine’s image of that remote folder.
If that’s reasonably accurate, then you are correct that a stay-open aplet is the way to go instead of a folder action. A stay-open idle handler looks like this:
on run
-- do stuff - this runs when the application is started to set things up if necessary
-- Here you could get the list of files currently in the remote folder, compare it to the previous list (saved as a property so it will "keep" when you shut down, or stored as a preference file) and for any file not contained in the previous list you do your thing, then update the list (your thing would be a handler perhaps).
end run
on idle
-- In this section, you periodically check the file list in the folder and if they're not in the old list, call your handler, etc.
return 60 -- do this every 60 seconds (or whatever you think reasonable so as not to "thrash" the LAN which has to pass the entire file list every time).
end idle
on quit
-- do stuff - for example, store the file list data in a pref file.
continue quit -- an essential step; you've grabbed the "quit" event with this handler, so now you have to inform the system that you're ready to complete that thread.
end quit
This method is much more reliable than an FA.