标签: applescript

插入USB驱动器后如何自动运行AppleScript?

我需要重命名并填充大约70个USB记忆棒.如果Applescript在插入时自动运行会使其更加简单.

applescript

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

Applescript 获取元素

这个 SO 答案在编写新 MacBook Retina 上屏幕分辨率更改的脚本时进一步指出了我。我被困在这里:

在此处输入图片说明

我可以使用此脚本到达此窗格:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preference.displays"
    reveal anchor "displaysDisplayTab" of current pane
    get elements of current pane
    tell application "System Events"

    end tell
    --get the name of every anchor of current pane
end tell
Run Code Online (Sandbox Code Playgroud)

但是,如果此窗格内容,如何知道如何选择位?例如,如何参考“缩放”单选按钮并选择 5 种可能的分辨率之一?谢谢

macos applescript

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

通过索引按升序对 Applescript 列表进行排序

我正在尝试对从一个文件夹创建的文件名列表进行排序。这是代码,因为它是最简单的形式。如果我运行这个 10 总是在 1 之后而不是 9。我在看什么。

set composer_list to {"Filename_1", "Filename_2", "Filename_3", "Filename_4", "Filename_5", "Filename_6", "Filename_7", "Filename_8", "Filename_9", "Filename_10", "Filename_11"}
simple_sort(composer_list)


--======================================= Sorting Handler =====================================
on simple_sort(my_list)
    set the index_list to {}
    set the sorted_list to {}
    repeat (the number of items in my_list) times
        set the low_item to ""
        repeat with i from 1 to (number of items in my_list)
            if i is not in the index_list then
                set this_item to item i of my_list as text
                if the …
Run Code Online (Sandbox Code Playgroud)

sorting applescript list

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

Applescript - 解析XML

我尝试创建Applescript以从.xfdf中提取值

XFDF

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <annots>
    <square color="#FF0000" creationdate="D:20130828114843+05'30'" date="D:20130828114901+05'30'" flags="print" name="Xi6cOkAWgWHcAhpfBkR5A7" page="0" rect="347.7599999991828,1041.8400000004283,453.5999999989341,1056.9600000003927" subject="Rectangle" title="1 im, awltest7 (AWLTEST7.IM)">
      <contents-richtext>
        <body>
          <p>Text Not Clear</p>
        </body>
      </contents-richtext>
      <popup open="yes" page="0" rect="453.5999999989341,944.4600000003926,573.5999999989341,1056.9600000003927" />
    </square>
    <square color="#FF0000" creationdate="D:20130828114910+05'30'" date="D:20130828114919+05'30'" flags="print" name="ptmmBKtfoDEbVzirMgZLnY" page="0" rect="511.1999999987987,1092.960000000308,550.7999999987057,1123.9200000002352" subject="Rectangle" title="2 im, awltest7 (AWLTEST7.IM)">
      <contents-richtext>
        <body>
          <p>Incorrect dimension</p>
        </body>
      </contents-richtext>
      <popup open="yes" page="0" rect="550.7999999987057,1011.4200000002352,670.7999999987056,1123.9200000002352" />
    </square>
    <square color="#FF0000" creationdate="D:20130828114956+05'30'" date="D:20130828115004+05'30'" flags="print" name="8LaAl2Upx4LEaQptQKXoZx" page="0" rect="355.67999999916424,731.5200000011573,431.99999999898483,750.2400000011135" subject="Rectangle" title="3 im, awltest7 (AWLTEST7.IM)">
      <contents-richtext>
        <body>
          <p>Incorrect Text</p>
        </body> …
Run Code Online (Sandbox Code Playgroud)

xml applescript xml-parsing xfdf

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

AppleScript 中的“end if”/“else if”不起作用?

我正在尝试使用具有多个按钮的对话框编写 AppleScript,每个按钮执行不同的命令。我的问题是 AppleScript 编辑器根据标题将“如果”或“否则”检测为语法错误。

例如:

set dialog to display dialog "Test" buttons {"1","2"}
set pressed to button returned of dialog
if pressed is equal to "1" then activate "Safari"
else if pressed is equal to "2" then beep
end if
Run Code Online (Sandbox Code Playgroud)

AppleScript 编辑器显示错误“语法错误:预期的行尾等,但发现“否则如果”。

有什么我做错了吗?

macos applescript

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

applescript,将文件夹及其内容移动到垃圾箱

任何人都可以指出如何将文件夹及其内容移动到mac上的垃圾文件夹?

我试过这个:

 tell application "Finder"
      set sourceFolder to POSIX file "/Library/Frameworks/SDL.framework"
      set destFolder to POSIX file "/Users/XXX/.Trash"
      move entire contents of folder sourceFolder to folder destFolder
 end tell
Run Code Online (Sandbox Code Playgroud)

内容都没有了,但不是 SDL.framework 文件夹。

此外,当我测试删除到垃圾箱文件夹的文件时,右键单击文件,没有“放回”意见。有谁知道为什么?

谢谢。

丽江

applescript

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

带有新行的击键字符串

考虑这个

set cannedResponse to "Hello,
Thanks for your support request!
We'll take a look at the issue and get back to you as fast as possible"

tell application "System Events" to keystroke cannedResponse
Run Code Online (Sandbox Code Playgroud)

它打印文本但没有返回字符。我怎样才能得到它们?

applescript

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

将多个参数从 Applescript 传递到终端命令脚本

我一直在试图弄清楚如何将多个参数从 Applescript 传递到终端命令脚本。例如,在运行终端命令文件时,您可以像这样以编程方式接收参数:

#!/bin/bash

var=$1

var=$2
Run Code Online (Sandbox Code Playgroud)

我一直在使用的 Applescript 代码如下供参考:

tell application "System Events" to set app_directory to POSIX path of (container of (path to me))

set thisFile to "Dev"

set testTarget to "/Users/lab/Desktop/TestTarget/"

do shell script "/Users/lab/Desktop/TempRoot/mycommand.command " & thisFile & testTarget with administrator privileges
Run Code Online (Sandbox Code Playgroud)

我认为我出错的地方是第二个参数的输入。当我只有一个参数时,它运行得很好:

do shell script "/path/to/command/mycommand.command" &var with administrative privileges
Run Code Online (Sandbox Code Playgroud)

我很好奇传递第二个参数的正确语法是什么。如果有人有任何建议,请告诉我!另外,如果您需要更多信息,我很乐意提供!

parameters macos bash terminal applescript

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

通过 ScriptMonitor.app 实用程序运行 AppleScript

当 AppleScript 通过系统范围的脚本菜单运行时,它们的进度会使用 ScriptMonitor 小程序(位于/System/Library/CoreServices/ScriptMonitor.app,在 OS X Yosemite 中引入)显示在菜单栏中。这使您可以随时了解正在运行的脚本、监控进度并轻松停止运行脚本。

脚本监视器图标

是否可以从脚本菜单外部通过 ScriptMonitor 运行 AppleScript,例如从终端或来自其他应用程序的系统调用?

我尝试了以下命令的各种排列,但都没有成功:

/System/Library/CoreServices/ScriptMonitor.app/Contents/MacOS/ScriptMonitor /PATH/TO/SCRIPT
Run Code Online (Sandbox Code Playgroud)

或者

open -a /System/Library/CoreServices/ScriptMonitor.app --args /PATH/TO/SCRIPT
Run Code Online (Sandbox Code Playgroud)

这很有用的原因是有许多帮助应用程序运行 AppleScripts 以响应事件,但往往不太擅长通知用户他们的成功或失败。

macos applescript automation system-calls

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

具有管理员权限的JXA等效项

在AppleScript中,您可以:

do shell script "echo 'I am (G)root'" with administrator privileges
Run Code Online (Sandbox Code Playgroud)

抱歉.无论如何,shell脚本可以在JXA中运行,如下所示:

var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("echo I am not root :(");
Run Code Online (Sandbox Code Playgroud)

但是,with administrator privileges在JXA中似乎没有相应的内容.有没有我错过的,或者我该怎么做呢?并且不要告诉我使用sudo.它不会起作用.

shell applescript equivalent javascript-automation

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