简单的 Apple 脚本在 Catalina 下工作,在 M1 MBA 的 Big Sur 下不起作用

编程入门 行业动态 更新时间:2024-10-24 08:28:59
本文介绍了简单的 Apple 脚本在 Catalina 下工作,在 M1 MBA 的 Big Sur 下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在我的 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 14:00:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   不起作用   简单   工作   Sur

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!