我在 AppleScript 中遇到了如下操作字符串的挑战:
First Last (first.last@hotmail.com)First Last- 所以需要移除第一个支架前面的空间。在 AppleScript 中执行此操作的最佳和最有效的方法是什么?
我需要使用 sudo 执行命令,并希望显示一个对话框窗口供用户输入其凭据。尝试使用 Applescript 自定义提示简直令人痛苦,并且使用内置的“以管理员权限执行 shell 脚本”不允许自定义窗口,因此用户知道请求来自何处。

当然,有一种方法可以显示一个窗口,让用户输入他们的凭据并将值发送回 sudo 以执行命令?cocoasudo看起来很有前途,但它也在提示窗口中写了“cocoasudo”,我需要用我的应用程序名称替换它。有没有人找到实现这种功能的解决方案?
我正在尝试修改一个带有文本文件的applescript,并使用文本文件的每一行创建一个新的待办事项:
set myFile to (choose file with prompt "Select a file to read:")
open for access myFile
set fileContents to read myFile using delimiter {linefeed}
close access myFile
tell application "Things"
repeat with currentLine in reverse of fileContents
set newToDo to make new to do ¬
with properties {name:currentLine} ¬
at beginning of list "Next"
-- perform some other operations using newToDo
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
相反,我希望能够简单地使用剪贴板作为数据源,这样我就不必每次都创建和保存文本文件,有没有办法加载剪贴板,并且对于每个换行符,执行newToDo 函数?
到目前为止,这是我的尝试,但它似乎不起作用并将整个剪贴板放在一行中,我似乎找不到合适的分隔符。
try
set oldDelims to AppleScript's text item delimiters -- save their …Run Code Online (Sandbox Code Playgroud) 尝试' '在我的 osascript 命令中包含引号时遇到了一个奇怪的问题。
如果我尝试转义一个正常的可转义字符,它工作正常。示例:osascript -e 'tell app "Finder" to display dialog "Te\\st"'来自 Finder 的对话框弹出,其中包含文本Test。
但是,当我在写出完整句子时尝试使用撇号时,就会出现问题。示例:osascript -e 'tell app "Finder" to display dialog "Te\'st"'当我运行它时,只剩下没有对话框,终端中的文本输入如下所示:
>
据我所知,这无论如何都应该起作用,但是,它没有。
我已经在 google.com 上搜索了几个小时,试图找到一种方法来做到这一点,但没有答案。Everywhere 是调整到最长的大小,但没有调整到指定的宽度。
Automator 或 AppleScript 中是否有任何方法可以将图像大小调整为指定的宽度,而不仅仅是最长的大小?我需要我的输出图像是一个特定的宽度(例如 200px)。
在升级到 Office 365 和 OSX 10.10 之前,以下脚本运行良好:
tell application "Microsoft Outlook"
set newMessage to make new outgoing message
tell newMessage
make new attachment with properties {file:"/Users/foo/file"}
end tell
open newMessage
end tell
Run Code Online (Sandbox Code Playgroud)
但现在它给出了这个错误信息:
execution error: Microsoft Outlook got an error: Error while saving the changed record property. (-2700)
程序是否已更改,或者这是 OSX 或 Outlook 中的错误?
有没有办法在不点击mac的情况下移动鼠标?我尝试使用 AppleScript 移动鼠标?但失败了?
tell application "Extra Suites"
ES move mouse {200,200}
end tell
Run Code Online (Sandbox Code Playgroud)
错误:预期的“给定”、“有”、“没有”、其他参数名称等。但找到了标识符。
有没有办法在applescript显示对话框和通知中使用自定义图标?
在 AppleScript 文档中,它说明了显示对话框:
with icon( text | integer )
要显示的图标的资源名称或 ID。
with icon(停止|注意|警告)要显示的图标类型。您可以指定以下常量之一:
- 停止(或 0):显示停止图标
- 注意(或 1):显示应用程序图标
- 警告(或 2):显示带有应用程序图标标记的警告图标
with icon( alias | file ) 指定 .icns 文件的别名或文件说明符。
所以看起来你可以使用自己的图标,但我无法让以下代码工作。
display dialog "Text" with icon "/Users/user/Desktop/asd.icns"
Run Code Online (Sandbox Code Playgroud)
它让我出现以下错误:“找不到资源。”
目标是甚至不使用显示对话框,而是使用显示通知。
我想要一个执行以下操作的 AppleScript:
Kdiff_full_call) 作为参数Downloads目录中我怎样才能在 AppleScript 中做到这一点?
Kdiff_full_call 具有以下模式: string1-string2 string3 string4
到目前为止,我有这个脚本:
on open location kdiff_full_call
set array to my theSplit(kdiff_full_call, "-")
-- set string1 ... ??
do shell script "/usr/bin/unzip -d " & quoted form of string1
end open location
on theSplit(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text …Run Code Online (Sandbox Code Playgroud) 我有一个脚本,我定期运行以使用 Applescript 打开/关闭灰度。它在 High Sierra 上运行良好,但在我使用 Mojave 时抛出异常。
tell application "System Preferences"
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.5 # Needed or else script fails
set theCheckbox to checkbox "Use grayscale" of window "Accessibility"
tell theCheckbox
# If the checkbox is not checked, check it to turn grayscale on
if not (its value as boolean) then
set checked to true
click theCheckbox
else # else turn grayscale …Run Code Online (Sandbox Code Playgroud)