这个文件是挂载的卷吗?
Is this file a mounted volume?
我的情况:
我正在尝试使用 Applescript 为我的桌面制作垃圾桶替代品。如果我双击它,我希望它打开 ~/.Trash
。如果我将文件或文件夹拖到它上面,我希望它将所述文件或文件夹移动到垃圾箱。而且,与这个问题相关的是,如果我将一个已安装的卷拖到它上面,我希望它弹出该卷。
我的代码:
on open droppeditems
set filesForTrash to droppeditems as text
if filesForTrash ends with ":" then
display dialog "1"
set found to false
repeat with volume in (list disks)
display dialog (volume as string)
if (volume as string) is (filesForTrash as string) then
set found to true
try
tell application "Finder"
eject filesForTrash
end tell
end try
end if
end repeat
if found is false then
try
tell application "Finder"
move filesForTrash to trash
end tell
end try
end if
else
try
tell application "Finder"
move filesForTrash to trash
end tell
end try
end if
end open
do shell script "open ~/.Trash"
我的问题:
我用 iDMG 创建了一个非常基本的 DMG 并安装了它。我将它拖到应用程序中,但在 repeat with volume in (list disks)
中它无法识别我拖到它的卷是在 list disks
中找到的卷之一,因此在 [=] 时尝试 tell application "Finder" to move filesForTrash
15=] 是一个卷,因此不能被删除。
我的理想方案:
我需要一种方法让我的代码接受卷,确定它们是卷,然后弹出它们而不是尝试将它们丢弃。
首先 droppeditems
是别名说明符的 list,将列表强制转换为文本连接 HFS 路径,代码无法运行。
您必须使用循环来分别处理每个掉落的物品。
这是一种不同的方法:
System Events
获取项目的 volume
并检查 POSIX path
以确定它是否是一个卷。
- 如果项目是一个卷并且可以弹出,则该卷将被弹出
- 如果该项目是一个体积且不可弹出,则不会发生任何事情。
- 否则该项目将被丢弃。
on open droppeditems
repeat with anItem in droppeditems
tell application "System Events"
set diskItem to disk item (anItem as text)
set itemVolume to volume of diskItem
set isVolume to ("/Volumes/" & itemVolume) is POSIX path of diskItem
end tell
tell application "Finder"
if isVolume and ejectable of disk itemVolume is true then
eject disk itemVolume
else if not isVolume then
move anItem to trash
end if
end tell
end repeat
end open
如果您还想删除不可弹出的卷,请在 else
之后删除 if not isVolume then
我的情况:
我正在尝试使用 Applescript 为我的桌面制作垃圾桶替代品。如果我双击它,我希望它打开 ~/.Trash
。如果我将文件或文件夹拖到它上面,我希望它将所述文件或文件夹移动到垃圾箱。而且,与这个问题相关的是,如果我将一个已安装的卷拖到它上面,我希望它弹出该卷。
我的代码:
on open droppeditems
set filesForTrash to droppeditems as text
if filesForTrash ends with ":" then
display dialog "1"
set found to false
repeat with volume in (list disks)
display dialog (volume as string)
if (volume as string) is (filesForTrash as string) then
set found to true
try
tell application "Finder"
eject filesForTrash
end tell
end try
end if
end repeat
if found is false then
try
tell application "Finder"
move filesForTrash to trash
end tell
end try
end if
else
try
tell application "Finder"
move filesForTrash to trash
end tell
end try
end if
end open
do shell script "open ~/.Trash"
我的问题:
我用 iDMG 创建了一个非常基本的 DMG 并安装了它。我将它拖到应用程序中,但在 repeat with volume in (list disks)
中它无法识别我拖到它的卷是在 list disks
中找到的卷之一,因此在 [=] 时尝试 tell application "Finder" to move filesForTrash
15=] 是一个卷,因此不能被删除。
我的理想方案:
我需要一种方法让我的代码接受卷,确定它们是卷,然后弹出它们而不是尝试将它们丢弃。
首先 droppeditems
是别名说明符的 list,将列表强制转换为文本连接 HFS 路径,代码无法运行。
您必须使用循环来分别处理每个掉落的物品。
这是一种不同的方法:
System Events
获取项目的 volume
并检查 POSIX path
以确定它是否是一个卷。
- 如果项目是一个卷并且可以弹出,则该卷将被弹出
- 如果该项目是一个体积且不可弹出,则不会发生任何事情。
- 否则该项目将被丢弃。
on open droppeditems
repeat with anItem in droppeditems
tell application "System Events"
set diskItem to disk item (anItem as text)
set itemVolume to volume of diskItem
set isVolume to ("/Volumes/" & itemVolume) is POSIX path of diskItem
end tell
tell application "Finder"
if isVolume and ejectable of disk itemVolume is true then
eject disk itemVolume
else if not isVolume then
move anItem to trash
end if
end tell
end repeat
end open
如果您还想删除不可弹出的卷,请在 else
if not isVolume then