on awake from nib theObject
tell theObject to register drag types {"file names"}
end awake from nib
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
repeat with thePath in thePaths
set theFile to (POSIX file thePath as string) as file specification
tell application "Finder"
make new alias file at desktop to theFile
end tell
end repeat
end if
end drop
but found this:
If you’re doing a drag and drop onto a Cocoa object in your interface you must avoid all use of the Finder in the ‘on drop the_object_ drag info drag_info_’ handler.- and this is true , Finder will hang for about 20 if called from the “on drop”, finally it will do his job but …
And i cant fin a work around for this…
My app: will create aliases of files droped in drop box.
Maybe someone already did that and can help me with this.
second of all: please post AppleScript Studio topics into the Xcode forum
third of all: does this work better?
on awake from nib theObject
tell theObject to register drag types {"file names"}
end awake from nib
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
createAliasFromList(thePaths)
end if
end drop
on createAliasFromList(L)
repeat with thePath in L
set theFile to (POSIX file thePath as alias)
tell application "Finder"
make new alias file at desktop to theFile
end tell
end repeat
end createAliasFromList
Thank you for your response . I didn’t now that for ApplescriptStudio i shall post in Xcode forum.
I have tryied the code you sugested, but it dosent work better. Finder will hang for about 20 sec, and then will create the alias.
Also, in order to not open other topic, id like to ask if its possible to share a variable between two applescripts (from the same project) in ApplescriptStudio.
I tested your code and there is indeed a long and annoying delay when creating the alias. I tried it separated out as a handler and changing it into a script object with the same delays. I’m not sure that there is a way around this using the Finder. A little searching on the web and there might be a command line solution, though it is not an off the shelf one. See this link:
http://osxutils.sourceforge.net/ osxutils is a bundle of powerful Mac-oriented command line utilities for viewing, editing and manipulating file meta-data.
which includes the command: mkalias
For sharing variables between script’s in AppleScript studio you need to make user defaults which store them in the plist file and are persistent between launches. (http://macscripter.net/viewtopic.php?id=24606 )
property theFile : {}
property thePAth : {}
property thePaths : {}
on clicked theObject
repeat with thePAth in thePaths
tell application "Finder"
make new alias file at desktop to (POSIX file thePAth)
end tell
end repeat
end clicked
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
repeat with thePAth in thePaths
set theFile to (POSIX file thePAth as string) as file specification
end repeat
end if
end drop
So, i added a button which (when pressed) will create the alias.
just move the repeat loop into the clicked handler and save the path list
property thePaths : {}
on clicked theObject
tell application "Finder"
repeat with onePath in thePaths
make new alias file at desktop to (POSIX file onePath as alias)
end repeat
end tell
end clicked
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
end if
end drop
Note: the class file specification is deprecated. Use alias instead