![](/img/trans.png)
[英]How to Get the Meeting Details from MS Outlook when the meeting window is Opened using Apple script
[英]Apple Script runs more than once when file is opened
我有一段代码用作文件夹操作,并不断监视该文件夹。 将新文件放入文件夹后,脚本将运行并输出一个对话框。 用户可以从对话框中打开或打印文件。 但是,当我选择打开按钮时,当尚未打开新文件时,代码将再次生成对话框。 这仅在打开文件时发生,而不在打印时发生。
有人可以帮忙吗? 代码如下
on adding folder items to theAttachedFolder after receiving theNewItems
set filepath to theNewItems as string
if filepath contains "HA" then
set theDialogText to "HA is in file name"
do shell script "afplay '/System/Library/Sounds/Submarine.aiff'"
display dialog theDialogText buttons {"Dismiss", "Print", "Go to "} default button "Go to order" with icon note
if result = {button returned:"Go to"} then
tell application "Finder"
open file filepath
end tell
else if result = {button returned:"Print"} then
tell application "Shelf Label Printer"
activate
print filepath
quit
end tell
display dialog "Printed" with icon note
end if
if filepath contains "OG" then
set theDialogText to "OG is in file name"
do shell script "afplay '/System/Library/Sounds/Submarine.aiff'"
display dialog theDialogText buttons {"Dismiss", "Print", "Go to"} default button "Go to order" with icon note
if result = {button returned:"Go to"} then
tell application "Finder"
open file filepath
end tell
else if result = {button returned:"Print"} then
tell application "Shelf Label Printer"
activate
print filepath
quit
end tell
display dialog "Printed" with icon note
编辑: Mojave正在有问题的iMac上运行。
这段代码中有一些问题点,任何问题都可能产生奇怪的行为,因此我对其进行了清理,以使其在我的机器上可以正常工作。 首先是新代码,然后是我所做的更改的重点...
on adding folder items to theAttachedFolder after receiving theNewItems
repeat with thisItem in theNewItems
set filepath to POSIX path of thisItem as string
if filepath contains "HA" or filepath contains "OG" then
set theDialogText to "HA or OG is in file name"
do shell script "afplay '/System/Library/Sounds/Submarine.aiff'"
tell application "System Events"
display dialog theDialogText buttons {"Dismiss", "Print", "Go to"} default button 3 with icon note
end tell
if result = {button returned:"Go to"} then
tell application "System Events"
open file filepath
end tell
else if result = {button returned:"Print"} then
tell application "Shelf Label Printer"
activate
print filepath
quit
end tell
display dialog "Printed" with icon note
end if
end if
end repeat
end adding folder items to
现在应该可以正常工作了...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.