Automator wifi专用备份

问题描述

当我连接到家庭网络时,我希望每周自动运行Mac上某些文件夹到云的备份。

场景:

检查wifi网络名称

如果是“家”,则执行备份

其他出口

我创建了一个日历事件来触发自动脚本。

我目前有两个bash脚本

  1. 确定我连接的wifi网络
  2. 执行备份(使用rclone)

我苦苦挣扎的部分是“如果,然后,其他”部分。

Bash脚本1:

/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F: '/ SSID/{print $2}'

尝试使用applescript

on run {input,parameters}
    
    if input is not ("home") then error number -128
    
    return input
    
end run

应在检测到家庭网络时运行的Bash脚本:

/usr/local/Cellar/rclone/1.52.1/bin/rclone copy "Source" Remote:folder

两个bash脚本都可以工作,但是我受条件部分的困扰....感激不尽。

解决方法

运行您的命令,我得到以下信息

❯ /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F: '/ SSID/{print $2}'
 Home

您会注意到Home之前有一个tiiiiiiiiny空格。文本实际上是<space>Home

您的问题在awk命令中。

当您将文本 SSID: Home除以:时,$1变成 SSID,而$2变成 Home。 (再次注意空格)。

您对applescript的输入正在寻找HomeHome Home不匹配。

注意间距和大小写。


第二,inputlist,而不是字符串。因此input is not ("home")将始终运行,因为您正在将其与字符串进行比较。

如果要将inputstring之类的string进行比较,则必须将 home转换为on run {input,parameters} if (input as string) is " home" then tell application "System Events" to display dialog "You are home." end if return input end run

AnalyticsListener

enter image description here