开发者

Store returned reference of tell Finder action in Applescript

I am building a Applescript droplet to automate some stuff. I have the following line:

tell application "Finder" to开发者_运维知识库 duplicate dropped

Dropped being a reference to the file that was dropped on the droplet. The documentation says that this returns a reference to the duplicated object.

I want to set myVariable to the reference that is returned but I can't find in any of the documentation how to actually do that!


if it's a droplet, be aware that the parameter is a list of aliases (you can drag more than one file!), and that if you duplicate a single finder item you will get a finder item, whereas if you duplicate more than one finder item, you will get a list of finder items. i.e. the return value of duplicate depends on the parameters sent to it.

AND... finder items are not very useful outside the finder. You'd be better off with aliases or POSIX paths.

So you probably need something like

on open (dropped)

tell application "Finder"
    set duplicate_Finder_items to duplicate dropped
end tell

-- convert the Finder reference for each duplicate item to an AppleScript alias

set duplicate_item_aliases to {}

if class of duplicate_Finder_items is list then
    repeat with i from 1 to number of items of duplicate_Finder_items
        set the end of duplicate_item_aliases to (item i of duplicate_Finder_items) as alias
    end repeat
else -- result was a single Finder item, not a list
    set duplicate_item_aliases to {duplicate_Finder_items as alias}
end if

repeat with f in duplicate_item_aliases
    set inf to (info for (f as alias))
    set n to name of inf
    display dialog "You duplicated a file. The duplicate is now known as " & n
end repeat

end open


The duplicate command allows for a location to be specified:

set theResult to duplicate reference ¬
     to insertion location ¬
     replacing boolean ¬
     routing suppressed boolean

Parameter, Required, Type, Description

direct parameter, required, reference, the object(s) to duplicate

replacing, optional, boolean, Specifies whether or not to replace items in the destination that have the same name as items being duplicated

routing suppressed, optional, boolean, Specifies whether or not to autoroute items (default is false). Only applies when copying to the system folder.

to, optional, insertion location, the new location for the object(s)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜