I have set up a drag and drop app that when a PDF is dropped on a window of the app it activates indesign and goes through a routine which eventually prints a postscript file, this all works really well.
The only issue I have with the drag and drop part is that when you release the PDF onto the window it takes about 30 odd seconds for the script to get going, at the end of this 30 seconds of inactivity you see what appears to be the PDF going back into the folder it was selected from, then the script kicks in, is this normal? as id like it all to be relatively quick.
I don’t think that is normal – I’ve never seen the file appear to go back to its folder unless your dragging operation isn’t successful, and that usually happens right away.
Do you have a log statement at the beginning of your script to see if it really takes 30 seconds to get going, or could it be that something in you script is taking that long?
I think you need to post some code, so we can see what’s going on.
thanks for the suggestions guys.
I’ve had a pretty good play and I think it’s this piece of code that is slowing things up, the desktop would only have one folder on it that ends with PROOF & that begins with Q, so it’s not like it needs to search for to much, once the app gets past this piece of code everything is as quick as it should be, so I’m a bit stumped as to what in this code is the possible issue.
tell application "Finder"
set _folders to (folders of desktop whose name ends with "PROOF")
repeat with _folder in _folders
set _Name to name of _folder
set name of _folder to (characters 1 thru -7 of _Name as text)
end repeat
set _folders to (folders of desktop whose name begins with "Q")
repeat with _folder in _folders
set _Name to name of _folder
count words of _Name
if the result is 2 then
set _NewName to (text 2 thru 7 of _Name) & (text 9 thru -1 of _Name)
else
set _NewName to (text 2 thru -1 of _Name)
end if
end repeat
set _FileSave to _NewName & "-" & _H as string
set the clipboard to _NewName & "-" & _H as string
set aFolder to _folders
set aPath to (aFolder as string)
end tell
I tried your code, adding “log (current date) as text” commands at the beginning and end, and it didn’t show any elapsed time, so I don’t know what’s different between your runs and mine. The only thing I had to make up was to define _H as a property with a value of “_modified” so the app would run. I had one folder ending in PROOF and 2 that started with Q to test the code.
ive tried logging etc etc, but still nothing really stands out as to why their is such a huge delay, ive broken the code down to the area that appears to be giving me grief, ive got one folder on the desktop called Q11111-PROOF, with one pdf in it, not sure what to do here.
script DROP_FOR_WEBAppDelegate
property parent : class "NSBox"
property dropBox : missing value
on draggingEntered_(info)
return current application's NSDragOperationCopy
end draggingEntered_
on draggingExited_(info)
dropBox's makeFirstResponder_(missing value)
end draggingExited_
on performDragOperation_(info)
log (current date) as text
tell application "Adobe InDesign CS5.5"
set myDoc to make new document with properties {document preferences:{page width:300, page height:300, facing pages:false}}
tell layout window 1
zoom given fit page
end tell
tell myDoc
set myLayer to make layer with properties {name:"Guides"}
tell page 1
make guide with properties {orientation:horizontal, location:"235.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"220", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"135.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"115.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"44", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"15", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"-5", item layer:myLayer}
end tell
end tell
-----------------------
tell application "Finder"
set _H to "H"
set _folders to (folders of desktop whose name ends with "PROOF")
repeat with _folder in _folders
set _Name to name of _folder
set name of _folder to (characters 1 thru -7 of _Name as text)
end repeat
set _folders to (folders of desktop whose name begins with "Q")
repeat with _folder in _folders
set _Name to name of _folder
count words of _Name
if the result is 2 then
set _NewName to (text 2 thru 7 of _Name) & (text 9 thru -1 of _Name)
else
set _NewName to (text 2 thru -1 of _Name)
end if
end repeat
set _FileSave to _NewName & "-" & _H as string
set the clipboard to _NewName & "-" & _H as string
set aFolder to _folders
set aPath to (aFolder as string)
end tell
tell application "Adobe InDesign CS5.5"
save document 1 to (choose file name default name _FileSave default location alias aPath)
end tell
-- REST OF CODE GOES HERE AND RUNS AS EXPECTED --
end tell
log (current date) as text
return true
end performDragOperation_
on applicationWillFinishLaunching_(aNotification)
my dropBox's registerForDraggedTypes_({"public.file-url"})
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
Did you try adding more logs of current time within this code you posted? I’m guessing that the delay has something to do with InDesign (which I don’t have and can’t test) – if you put a log before and after each tell block, it would pinpoint the delay better.
the indesign part runs with no issues at all, very quick, theirs a big delay in the finder tell block though
2011-10-28 09:18:29.207 DROP FOR WEB[30466:707] Friday, October 28, 2011 9:18:29 AM
2011-10-28 09:18:29.495 DROP FOR WEB[30466:707] Friday, October 28, 2011 9:18:29 AM
2011-10-28 09:18:29.496 DROP FOR WEB[30466:707] Friday, October 28, 2011 9:18:29 AM
2011-10-28 09:18:53.796 DROP FOR WEB[30466:707] Friday, October 28, 2011 9:18:53 AM
script DROP_FOR_WEBAppDelegate
property parent : class "NSBox"
property dropBox : missing value
on draggingEntered_(info)
return current application's NSDragOperationCopy
end draggingEntered_
on draggingExited_(info)
dropBox's makeFirstResponder_(missing value)
end draggingExited_
on performDragOperation_(info)
log (current date) as text --
tell application "Adobe InDesign CS5.5"
set myDoc to make new document with properties {document preferences:{page width:300, page height:300, facing pages:false}}
tell layout window 1
zoom given fit page
end tell
tell myDoc
set myLayer to make layer with properties {name:"Guides"}
tell page 1
make guide with properties {orientation:horizontal, location:"235.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"220", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"135.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"115.5", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"44", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"15", item layer:myLayer}
make guide with properties {orientation:horizontal, location:"-5", item layer:myLayer}
end tell
end tell
end tell
log (current date) as text -- logs shows no issue to here
-----------------------
log (current date) as text --
tell application "Finder"
set _H to "H"
set _folders to (folders of desktop whose name ends with "PROOF")
repeat with _folder in _folders
set _Name to name of _folder
set name of _folder to (characters 1 thru -7 of _Name as text)
end repeat
set _folders to (folders of desktop whose name begins with "Q")
repeat with _folder in _folders
set _Name to name of _folder
count words of _Name
if the result is 2 then
set _NewName to (text 2 thru 7 of _Name) & (text 9 thru -1 of _Name)
else
set _NewName to (text 2 thru -1 of _Name)
end if
end repeat
set _FileSave to _NewName & "-" & _H as string
set the clipboard to _NewName & "-" & _H as string
set aFolder to _folders
set aPath to (aFolder as string)
end tell
log (current date) as text -- long delay to here
tell application "Adobe InDesign CS5.5"
close active document saving no
--save document 1 to (choose file name default name _FileSave default location alias aPath)
end tell
-- REST OF CODE GOES HERE AND RUNS AS EXPECTED --
-- end tell
--log (current date) as text
return true
end performDragOperation_
on applicationWillFinishLaunching_(aNotification)
my dropBox's registerForDraggedTypes_({"public.file-url"})
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
I think I’ve found your problem, but I don’t understand why it’s a problem. It seems that putting the finder code inside the performDragOperation method is what is slowing down the process. I have to say that I don’t understand what you are doing with this drag operation since you never do anything with the file that you drag in. In any case, I solved the delay problem by putting a performSelector_withObject_afterDelay_ statement in the performDragOperation method, and moved all the finder code out:
on draggingEntered_(info)
return current application's NSDragOperationCopy
end draggingEntered_
on draggingExited_(info)
dropBox's makeFirstResponder_(missing value)
end draggingExited_
on performDragOperation_(info)
performSelector_withObject_afterDelay_("doFinderStuff", missing value, 0.1)
return true
end performDragOperation_
on doFinderStuff()
log (current date) as text --
tell application "Finder"
set _H to "H"
set _folders to (folders of desktop whose name ends with "PROOF")
repeat with _folder in _folders
set _Name to name of _folder
set name of _folder to (characters 1 thru -7 of _Name as text)
end repeat
set _folders to (folders of desktop whose name begins with "Q")
repeat with _folder in _folders
set _Name to name of _folder
tell me to log _Name as text
count words of _Name
if the result is 2 then
set _NewName to (text 2 thru 7 of _Name) & (text 9 thru -1 of _Name)
else
set _NewName to (text 2 thru -1 of _Name)
end if
end repeat
set _FileSave to _NewName & "-" & _H as string
set the clipboard to _NewName & "-" & _H as string
set aFolder to _folders
set aPath to (aFolder as string)
end tell
log (current date) as text -- Very short delay now!
end doFinderStuff
on applicationWillFinishLaunching_(aNotification)
dropBox's registerForDraggedTypes_({"public.file-url"})
end applicationWillFinishLaunching_
wow, now that’s fast, really appreciate you looking further into this for me.
What I do after the file is dropped is create an ID document that places the pdf in a specific position
on a specific sized document, saves the file then post scripts it to a specific hot folder, then closes the
file.
I do a lot of repetitive single colour job’s, they all use a the same sized document, so I can speed up my
through put by just drag and drop of file, job done, no opening up folders, entering this and that,
gotta love automation aye.
Just for completeness, here is one way to accomplish the same thing using the file manager instead of Finder. In this case, it works fine to have the code inside the performDragOperation method:
on performDragOperation_(info)
set _folders to current application's NSMutableArray's alloc()'s init()
set theFolder to current application's NSString's stringWithString_(POSIX path of (path to desktop as string))
set fm to current application's NSFileManager's defaultManager()
set desktopArray to fm's contentsOfDirectoryAtPath_error_(theFolder, missing value)
repeat with anItem in desktopArray
set len to anItem's |length|()
set fullPath to theFolder's stringByAppendingString_(anItem)
set {aBool, isDirectory} to fm's fileExistsAtPath_isDirectory_(fullPath, reference)
if isDirectory as integer is 1 and anItem's hasSuffix_("PROOF") as integer is 1 then
set anItem to anItem's substringToIndex_({len - 6})
set newPath to theFolder's stringByAppendingString_(anItem)
fm's moveItemAtPath_toPath_error_(fullPath, newPath, missing value)
end if
if isDirectory as integer is 1 and anItem's hasPrefix_("Q") as integer is 1 then
_folders's addObject_(anItem)
if anItem's componentsSeparatedByString_(" ")'s |count|() as integer is 2 then
set anItem to anItem's substringFromIndex_({1})
set _NewName to anItem's stringByReplacingCharactersInRange_withString_({6, 1}, "")
log _NewName
else
set _NewName to anItem's substringFromIndex_({1})
log _NewName
end if
end if
end repeat
set _FileSave to (_NewName as text) & "-H"
set the clipboard to _FileSave
set aPath to ((_folders as list) as string)
log aPath
return true
end performDragOperation_
Thanks for spending the time to demonstrate how to use NSFileManager
for this particular style of use, I don’t really understand it at the moment but will research and gain some more knowledge, to get a better understanding.