标签: applescript

从 Mail.app 获取撰写窗口中的消息

我正在尝试制作一个脚本,该脚本将获取我在 Mail 中撰写的电子邮件的内容,对数据进行处理,然后发送邮件。我知道如何使用 AppleScript 从头开始​​制作和发送新消息,但我找不到一种方法来获取我已经在编写的消息。我不在乎使用什么语言,我愿意尝试不同的电子邮件客户端。谢谢你的帮助!

email macos applescript

5
推荐指数
1
解决办法
1272
查看次数

为什么简单的 osascript 命令在 OS X Lion 中失败?

我有两个非常简单的 OSA 脚本来允许在实验室环境中登录和注销计算机。当通过 ARD 推送时,这些脚本在 Snow Leopard 中完美运行,在 ssh 会话中交互,但它们在运行 Lion 的机器上失败。

精简到它的基本要素,注销脚本如下所示:

osascript -e '告诉应用程序“系统事件”注销'

  • 直接从机器上的交互式 shell 运行时有效
  • 从 ARD 推送时有效
  • 从 ssh 会话运行时出现“执行错误:变量 out 未定义。(-2753)”失败
  • 当脚本编译为 .scpt 时有效,然后从 ssh 运行(例如“/usr/bin/osacript logout.scpt”)

登录脚本直接基于此。显示问题的精简版本是:

osascript -e '将应用程序“系统事件”告诉按键“前端”'

  • 直接从交互式会话运行时有效
  • 从 ARD 推送时有效
  • FAILS with execution error: 发生了 -10810 类型的错误。(-10810) 从 ssh 运行时
  • 当作为编译的 scpt 运行并从 ssh 运行时有效

因为这些脚本交互工作良好,并且因为它们在 Snow Leopard 中的所有模式下都工作正常,所以我认为 osascript 中的某些内容一定发生了变化,但我不知道是什么,并且错误消息不是很具有描述性。欢迎大家提出意见。

macos applescript

5
推荐指数
1
解决办法
2512
查看次数

通过 AppleScript 发送带有附件的电子邮件

所以我希望能够使用 applescript 发送带有附件的电子邮件。我有一位老师经常让我们做实验并要求我们通过电子邮件发送它们,所以我决定结合榛子和 Applescript 来使这更容易。

基本上,当我将文档导出到文件夹中的 pdf 时,榛子会检测到它并将其发送到另一个文件夹,然后该文件夹调用发送带有附件的电子邮件所需的脚本。完成后,淡褐色将文件放回原始文件夹中,并在名称后附加一个 _sent 以便它不会再次发送。(除非文件刚刚导出为 pdf,否则该文件夹始终为空)

我的问题是这些文件没有附加到电子邮件中。(大多数时候我的脚本会出错,说它没有成功运行,但这不是重点)。

我在使用 automator 时遇到了同样的问题,没有附加文件。我尝试了几个代码,但总是遇到同样的问题。发送的电子邮件不附带任何文件。这是代码:

tell application "Finder"
set folderPath to folder "Macintosh HD:Users:user_directory:Desktop:Send_Mail"
set fileList to name of file 1 in folderPath
end tell

set theSubject to fileList
set theBody to "Hello sir. Here is my " & fileList
set theAddress to "Some Email"
set theAttachment to fileList
set theSender to "Some Sender"

tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject,         content:theBody & return …
Run Code Online (Sandbox Code Playgroud)

email applescript attachment automator

5
推荐指数
1
解决办法
2万
查看次数

在 Applescript 的 UI 脚本中使用 AXIdentifier

10.7.4 OSX Lion Applescript

我正在使用一个具有静态文本元素的应用程序(内部内置且没有 Applescript 字典),我想复制到剪贴板并发送到另一个应用程序,但我很难让它工作。

我用于定位元素的脚本如下所示:

Tell application "System Events" to set frontmost of process "*application*" to true
Tell application "System Events"
    Tell process "*application*" 
        Tell static text 1 of tab view 1 scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1
            keystroke "a" using command down
            delay 0.1
            keystroke "c" using command down
            delay 0.1
        end tell
    end tell
end tell
end tell
Run Code Online (Sandbox Code Playgroud)

会发生的情况是,每次我在应用程序的不同位置(有许多文本字段)单击时,错误元素中的错误文本都会被复制到剪贴板。

我在 UI Accessor/Accessibility Accessor …

scripting user-interface applescript

5
推荐指数
1
解决办法
3153
查看次数

使用AppleScript检查应用程序是否存在

此代码不适用于不存在的应用程序,因为它会提示用户查找"FooApp"(我不想与用户交互):

get exists application "FooApp"
Run Code Online (Sandbox Code Playgroud)

此代码仅适用于进程名称与其应用程序名称匹配的应用程序,该应用程序名称涵盖大多数应用程序,

tell application "System Events"
    get exists application process "FooApp"
end tell
Run Code Online (Sandbox Code Playgroud)

(例如在我的机器上"OmniGraffle Professional"是一个进程名称,但相应的应用程序名称是"OmniGraffle Professional 4".)

applescript

5
推荐指数
2
解决办法
8502
查看次数

AppleScript UI Scripting 通常很慢,还是我的脚本,或其他什么?

我是 AppleScript 的新手,我只是在深入研究 UI 脚本。我正在尝试为程序 TypeIt4Me 创建一个脚本,这是一个不支持 AppleScript 的菜单栏实用程序(文本扩展)。

我提议的脚本将利用系统事件单击其菜单栏图标,键入五次,一次,然后返回。但是,AppleScript 在单击图标和执行第一次击键之间会暂停很长时间,以至于这作为脚本是不切实际的。下面是第一次点击和一次按下的版本。

tell application "System Events"

click menu bar item 1 of menu bar 2 of application process "TypeIt4Me"
key code 125 -- ie "down"

end tell
Run Code Online (Sandbox Code Playgroud)

这可能是我的代码的问题吗?某个地方的设置?AppleScript 一般?谢谢。

applescript

5
推荐指数
1
解决办法
2503
查看次数

让一个脚本等到最后一个脚本完成

我有一个脚本,它有两个苹果脚本,可以打开一个新选项卡并执行命令。我希望第二个苹果脚本等到第一个苹果脚本的命令行操作完成。在它继续之前,我宁愿不必只睡 x 久。

有没有办法做到这一点?

这是我所拥有的:

 osascript -e 'tell application "Terminal" to activate' \
 -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
 -e 'tell application "Terminal" to do script "cd '$current_dir'" in selected tab of the front window' \
 -e 'tell application "Terminal" to do script "./my_script arg1" in selected tab of the front window'

 ------ Wait until this process is finished -------

 osascript -e 'tell application "Terminal" to activate' \
 -e 'tell …
Run Code Online (Sandbox Code Playgroud)

shell applescript

5
推荐指数
1
解决办法
6577
查看次数

如何在 Applescript 中调用 Automator 变量?

在此处输入图片说明

所以我有一个显示对话框的 Applescript,然后自动机将变量设置为条目

例子 。. . 输入“AAAAAAA”查询变量将是“AAAAAAA”

我正在尝试找出一种在运行我的下一个 applescript 时调用变量的方法

我知道如何通过使用 sys.argv 1和 stdin -> 参数来使用 Python shell 脚本

我怎样才能用 Applescript 实现这一点?

我看到了一个类似的帖子标题,但答案没有解决这个问题

variables macos applescript arguments automator

5
推荐指数
1
解决办法
1万
查看次数

无法理解在 Applescript 中分配变量时发生的错误

我是 applescript 甚至这个社区的新手,所以这个问题似乎很奇怪。如果是这样,我很抱歉。但是我在谷歌搜索中找不到答案。所以让我问一下。

当我运行代码时

tell application "Evernote"
    set theNote to item 1 of selection
    set theTitle to (title of theNote)
end tell
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,说

/var/folders/fm/k76y42cs1y98bjwfyf951q1r0000gn/T/vbkvTSQ/55:47:53: execution error: Evernote got an error: Can’t make item 1 of selection into type specifier. (-1700)
Run Code Online (Sandbox Code Playgroud)

但如果我跑到下面

tell application "Evernote"
    set theNote to (selection)
    set theNote to item 1 of theNote
    set theTitle to (title of theNote)
end tell
Run Code Online (Sandbox Code Playgroud)

我可以得到预期的结果。

为什么会发生这个错误?我看不到两个代码的区别。

applescript

5
推荐指数
1
解决办法
742
查看次数

来自Sandboxed应用程序的AppleScript`activate`不会将窗口带到前台

我试图从沙盒macOS应用程序打开系统偏好设置,以便用户可以手动启用某个偏好设置.

AppleScript的 activate

将应用程序带到前端,必要时启动它.

我正在运行macOS 10.13.6和Xcode 10.0.部署目标设置为OS X 10.11.

我从沙盒应用程序运行以下AppleScript:

let script = """
             tell application "System Preferences"
                 activate
                 set current pane to pane id "com.apple.preferences.extensions"
             end tell
             """
let appleScript = NSAppleScript(source: script)
var errorInfo: NSDictionary? = nil
appleScript?.executeAndReturnError(&errorInfo)
Run Code Online (Sandbox Code Playgroud)

我还添加了一个脚本目标Sandbox Entitlement,使系统首选项能够显示窗格:

<key>com.apple.security.scripting-targets</key>
<dict>
    <key>com.apple.systempreferences</key>
    <array>
        <string>preferencepane.reveal</string>
    </array>
</dict>
Run Code Online (Sandbox Code Playgroud)

一旦我添加了权利,这有点起作用.如果关闭系统首选项应用程序,则会启动它并打开正确的窗格.

该errorInfo词典是零,因此不会造成错误信息.

在控制台中,我看到一条消息,可能是不相关的日志垃圾邮件:

AppleEvents:收到mach msg,它不是getMemoryReference中预期的复杂类型.

但是,该应用程序不会激活."系统偏好设置"窗口未出现在前面.该应用程序导航到正确的选项卡,但不会作为activate状态的文档到达前台.它仍然在任何其他前景窗口后面.

在关闭"系统偏好设置"的情况下,应用程序会启动.但是,在您单击停靠图标之前,窗口不会添加到前景或背景中的屏幕上.然后出现窗口,已导航到正确的窗格.

为什么应用程序没有激活?

是否还有其他需要的Sandbox Entitlements可以激活"系统偏好设置"窗口?

macos cocoa applescript entitlements appstore-sandbox

5
推荐指数
1
解决办法
467
查看次数