如果和其他与附件AppleScript

时间:2019-01-09 04:45:01

标签: 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

1 个答案:

答案 0 :(得分:0)

要始终访问您的桌面,最好使用“桌面文件夹的路径”。 另外,使用功能“存在”检查桌面上是否存在图像文件,如果不存在,只需使用“返回”终止脚本即可:

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存在于桌面上。