applescript - if 和 else 带有附件 applescript
问题描述
每天我都会发送一封附有图片的电子邮件
我在我的 iPhone 中截取屏幕截图并上传到 iCloud,这出现在我的桌面 mac 中,所以,我的脚本从桌面获取这张图片,然后发送它。
但它需要一个“if”或“else”才能知道是否有图像。
如果有图片:发送它 如果没有图片:不要发送它
set recipientName to "name"
set recipientAddress to "Mail@mail.com"
set theAttachment to POSIX file "user/desktop/image.png"
set theSubject to "theSubject"
set theContent to "message"
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Add attachment
make new attachment with properties {file name:theAttachment} at before the last paragraph
##Pause
delay 3
##Send the Message
--send
end tell
end tell
解决方案
要始终处理您的桌面,最好使用“桌面文件夹路径”。另外,使用“exists”函数检查桌面上是否存在图像文件,如果不存在,只需使用“return”终止脚本:
set theAttachment to ((path to desktop folder) as string) & "image.png"
tell application "Finder"
if not (theAttachment exists) then return -- image does not exist, then termination
end tell
如果您的脚本在这 4 行之后继续,则表示文件 image.png 存在于您的桌面上。
推荐阅读
- java - WebDriverException:断开连接:即使提供最新 chromedriver 的正确路径,也无法连接到渲染器
- c# - 是否可以创建带有附件的日历事件?
- react-native - 清除 TextInput 文本时的清除状态
- c# - WPF 动态网格
- elasticsearch - 弹性搜索 - 如何在两种类型之间连接数据?
- pycharm - 尽管在 Keymap 中显示,但 CTRL-R 在 Pycharm 中不起作用
- integral - 通过 EES 中的子程序/模块生成 IntegralTable
- git - Git 流程澄清 Hotfix 和 RC 的存在?
- ruby-on-rails - 单击选项卡时防止滚动到顶部
- sql - 从 SQL Server 中删除最后一条记录?