下面是一个使用AppleScript的示例代码,可以根据团队成员的名字将文件复制到预设目录。
-- 设置团队成员名字和对应的目标目录
set memberDirectories to {{"John", "Macintosh HD:Users:John:Documents"}, ¬
{"Jane", "Macintosh HD:Users:Jane:Documents"}, ¬
{"Mike", "Macintosh HD:Users:Mike:Documents"}}
-- 获取当前用户的用户名
set currentUserName to (do shell script "echo $USER")
-- 查找当前用户的目标目录
set targetDirectory to missing value
repeat with member in memberDirectories
if item 1 of member is equal to currentUserName then
set targetDirectory to item 2 of member
exit repeat
end if
end repeat
if targetDirectory is missing value then
display dialog "当前用户没有对应的目标目录。" buttons {"OK"} default button 1
else
-- 选择需要复制的文件
set selectedFiles to choose file with multiple selections allowed
-- 复制文件到目标目录
repeat with theFile in selectedFiles
tell application "Finder"
duplicate theFile to folder targetDirectory with replacing
end tell
end repeat
display dialog "文件已成功复制到目标目录。" buttons {"OK"} default button 1
end if
在这个示例中,我们首先设置了团队成员的名字和对应的目标目录。然后,获取当前用户的用户名,并查找对应的目标目录。如果找到了目标目录,就允许用户选择需要复制的文件,并将文件复制到目标目录中。如果当前用户没有对应的目标目录,会显示一个错误提示框。复制过程完成后,会显示一个成功提示框。
请注意,示例代码中的目标目录是硬编码的,根据实际情况修改成相应的目录路径。另外,此代码仅适用于Mac操作系统。