简单的 Apple 脚本在 Catalina 下工作,在 M1 MBA 的 Big Sur 下不起作用 [英] Simple Apple Script works under Catalina, doesn't work under Big Sur on M1 MBA

查看:19
本文介绍了简单的 Apple 脚本在 Catalina 下工作,在 M1 MBA 的 Big Sur 下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 2013 MBP 上开发了一个脚本(工作正常),旨在稍后在一系列 M1 MBA 上运行它(在那些上根本不起作用).所以我按照这种方法.测试脚本在 2013 MBP 上运行得非常好,但在 M1 上也没有显示任何生命迹象.

I developed a script on my 2013 MBP (works fine), aiming to run it later on a series of M1 MBA's (doesn't work at all on those). So I created a simple test script following this method. The test script runs perfectly fine on the 2013 MBP but also doesn't show any sign of life on the M1.

#!/usr/bin/osascript

set mySSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'"
display notification mySSID
display alert mySSID

chmod +x 使可执行文件,然后移动到/usr/local/bin/在 M1 上,我必须创建 bin 文件夹,因为/usr/local/

made executable by chmod +x, then moved to /usr/local/bin/ On the M1 I had to create the bin folder as there wasn't any under /usr/local/

然后在 ~/Library/LaunchAgents 文件夹中创建一个 plist:

Then created a plist in the ~/Library/LaunchAgents folder:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.my.checkssid</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/checkSSID</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>10</integer></dict>
</plist>

此方法已被贡献者确认有效.

This method was confirmed to work by the contributor.

我也重新启动了 M1,但这也不起作用.当我将 plist 放入 ~/Library/LaunchAgents 并重新启动机器时,当我 grep 列表并返回- 0 com.my.checkssid"时,plist 处于活动状态.

I also restarted the M1 but that also doesn't work. When I put the plist in ~/Library/LaunchAgents and restart the machine, the plist is active when I grep a list and returns "- 0 com.my.checkssid".

plutil 返回 0(无错误)

plutil returns 0 (no errors)

脚本在 M1 上通过脚本编辑器运行良好

The script runs fine on the M1 from the script editor

当我将 plist 放入 ~/Library/LaunchAgents 并重新启动时,plist 处于活动状态.我可以使用launchctl unload <...>"

when I put the plist in ~/Library/LaunchAgents and reboot, the plist is active. I can unload it by using "launchctl unload <...>"

有没有其他方法可以查看脚本是否被调用?

Is there another way to see if the script is called at all?

有什么线索吗?

谢谢,皮特

推荐答案

我很想知道这是否有效,我还没有升级到 Big Sur 和 M1:

I'd be interested to know whether this works, having not yet upgraded to Big Sur nor the M1:

#!/usr/bin/osascript
use framework "CoreWLAN"
use scripting additions

get the ssid() of the sharedWiFiClient()'s interface() ¬
    of the current application's CWWiFiClient as text

display alert result

这篇关于简单的 Apple 脚本在 Catalina 下工作,在 M1 MBA 的 Big Sur 下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆