【发布时间】:2017-12-01 22:35:55
【问题描述】:
刚开始在这里编写苹果脚本并寻求帮助。我正在尝试使用苹果脚本创建一个 IF 语句,但似乎无法让它工作。
如果脚本使用指定的文件执行,则计划发送一个消息并附加一个文件,如果没有,则只发送文本。
例如:
纯文本示例: 图像 5555555555 "hi" "NoAttachment"
文本 + 文件示例: 图像 5555555555 "hi" "/location/test.jpg"
这是我正在使用的脚本: https://gist.github.com/aktau/8958054
但在底部进行了以下更改:
on run {targetBuddyPhone, targetMessage, targetFile}
tell application "Messages"
-- if Messages.app was not running, launch it
set wasRunning to true
if it is not running then
set wasRunning to false
launch
close window 1
my waitUntilRunning("Messages", 1)
close window 1
end if
-- send the message
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
set targetFileSend to targetFile
if targetFileSend = "NoAttachment" then
send targetMessage to targetBuddy
else
send POSIX targetFileSend to targetBuddy
send targetMessage to targetBuddy
end if
-- if the app was not running, close the window
if not wasRunning
close window 1
end if
end tell
end run
当我执行脚本时,我得到: 1635:1649:语法错误:预期行尾但找到标识符。 (-2741)
我在这里做错了什么?与使用触发器“NoAttachment”相比,使用空值会更好吗?
非常感谢任何帮助!
【问题讨论】:
-
尝试添加单词...“文件”..在“POSIX”之后
send POSIX file targetFileSend to targetBuddy
标签: applescript