我有一个 Mac OS X 应用程序,它也是一个协议处理程序(就像 Safari 是 HTTP 和 HTTPS 协议的协议处理程序一样)。因此,当用户在任何应用程序中单击 myscheme://some-kind-of-info 形式的链接时,我的应用程序将启动来处理该链接。
现在我需要能够确定应用程序是通过此类链接单击启动的,还是通过任何其他方法启动的。换句话说,除了点击链接之外,它是通过任何方法启动的。(在这些情况下,我希望应用程序保持打开状态,但如果它是通过链接启动的,它应该退出并忽略该链接。这样它仅在已经运行时运行。)
应用程序在启动时是否有某种方法可以内省并发现它是通过标准方法而不是 AppleScript GetURL 事件启动的?我想通过记录的方法找出答案,而不是 - 例如 - 只是让我的应用程序仅在运行半秒后打开这些链接。
set message to "Hello world "
set message to message & message
Run Code Online (Sandbox Code Playgroud)
这会产生错误。连接字符串的正确方法是什么?我需要使用与在循环中使用它相同的变量名。
或者用简短的 PHP 风格
$message = 'Hello world ';
$message .= $message
Run Code Online (Sandbox Code Playgroud) 只是想知道我是否可以将 Automator 中的“看我做”事件转换为 applescript,然后编辑生成的代码?我有一个在 Google 中输入查询(即 Apple1)的记录,但我希望查询为记录的每个循环增加 ++,因此结果是 Apple1,然后下一个循环将是 Apple2、Apple3等等。我知道增量在编程中是基本的,但我只是不确定如何使用 Automator 和/或 applescript 来做到这一点。任何帮助将不胜感激。
通知警报在 Applescript 中很容易编程:
osascript -e 'display notification "notification text content" with title "Alert!" sound name "Purr"'.
但是,我还没有找到解释如何使用按钮对它们进行编程的网页或 StackOverflow 问题,类似于 App Store 纠缠您升级到 OS X Yosemite 时出现的类型。此外,语法将通过命令使用osascript -e。
我如何通过带有按钮的通知中心编写 Applescript 警报?
提前致谢。
我正在尝试NSArray从NSAppleEventDescriptor. 几年前有人问过一个类似的问题,尽管解决方案返回一个NSString.
NSString *src = [NSString stringWithFormat: @"return {\"foo\", \"bar\", \"baz\"}\n"];
NSAppleScript *exe = [[NSAppleScript alloc] initWithSource:src];
NSAppleEventDescriptor *desc = [exe executeAndReturnError:nil];
NSLog(@"%@", desc);
// <NSAppleEventDescriptor: [ 'utxt'("foo"), 'utxt'("bar"), 'utxt'("baz") ]>
Run Code Online (Sandbox Code Playgroud)
我不确定我需要什么描述符函数来将值解析为数组。
具体来说,我需要检索当前用户的 HOME 变量的值。但我希望答案一般适用于任何环境变量。
我有一个脚本,用于查找名称并搜索与另一个变量的匹配项。
它工作正常,但是如果变量 1 是“Name Demo”而变量 2 是“Demo Name”,则脚本找不到匹配项。
set nameMatchTXT to ""
if NameOnDevice contains theName then
set nameMatch to theName & " : Name Match"
end if
Run Code Online (Sandbox Code Playgroud)
无论如何改变这个以找到匹配的顺序?PS 脚本正在寻找单词通配符,有时处理双位字符可能会很困难。
简而言之 - Mac 自动化的 JavaScript 相当于 AppleScript 的as «class utf8»什么?
我有一个 unicode 字符串,我正在尝试使用 JavaScript for Mac Automation 将其写入文本文件。
将字符串写入文件时,任何存在的 unicode 字符都会成为文件中的问号 (ASCII char 3F)。
如果这是一个 AppleScript 脚本而不是 JavaScript 脚本,我可以通过添加as «class utf8»原始语句来解决这个问题,如 Takashi Yoshida 的博客 ( https://takashiyoshida.org/blog/applescript-write-text-as-utf8-string -到文件/)。
但是,该脚本已经用 JavaScript 编写,因此我正在寻找与此 AppleScript 语句等效的 JavaScript。Apple 关于原始语句的页面仅针对 AppleScript ( https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_raw_data.html )。
要编写文件,我使用 Apple 自己的writeTextToFileJavaScript 函数示例(https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ReadandWriteFiles.html#//apple_ref/doc/uid/TP40016239- CH58-SW1 )。as根据 StandardAdditions 字典,我向以下调用添加了一个参数:
// Write the new content to the file
app.write(text, { to: openedFile, startingAt: …Run Code Online (Sandbox Code Playgroud) open http://localhost:8080每次在终端中运行都会打开一个新选项卡。
create-react-app 如何重用现有的浏览器选项卡(如果可用)?
看起来这里是魔法发生的地方:
function startBrowserProcess(browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab …Run Code Online (Sandbox Code Playgroud) 我正在制作一个脚本,它更新我的 macOS Safari 上的书签,以始终将我订阅的所有 subreddits 作为特定文件夹中的单个书签。我已经到了在 Python 中将所有 subreddits 作为元组排序列表的地步,将想要的书签名称作为第一个元素,将书签 url 作为第二个元素:
bookmarks = [
('r/Android', 'https://www.reddit.com/r/Android/'),
('r/Apple', 'https://www.reddit.com/r/Apple/'),
('r/Mac', 'https://www.reddit.com/r/Mac/'),
('r/ProgrammerHumor', 'https://www.reddit.com/r/ProgrammerHumor/')
]
Run Code Online (Sandbox Code Playgroud)
如何清除 Safari 中的 subreddit 书签文件夹并在该文件夹中创建这些新书签?
到目前为止,我一直在使用 Python,但是从 Python 程序调用外部 AppleScript 或 Shell 脚本是没有问题的。
这是想要的结果的图像,每个书签都链接到各自的 subreddit 网址:
applescript ×10
macos ×4
javascript ×2
automation ×1
automator ×1
cocoa ×1
contain ×1
if-statement ×1
increment ×1
launch ×1
objective-c ×1
python ×1
safari ×1
terminal ×1
xcode ×1