我一直试图通过编写几行简单的代码来探索AppleScript。我尝试过写一小段内容,以便我可以访问可用的Wi-Fi列表,然后输入密码到所说的Wi-Fi。
到目前为止,我已经达到了识别Wi-Fi可用的程度,但不允许我将Wi-Fi变成类型字符串。我已经编写了从列表中选择Wi-Fi的代码,但我无法弄清楚如何将Wi-Fi变成列表。
有人能帮我解决这个问题吗?
display dialog "Wifi Selector © Afnaan Qureshi"
set main to display dialog " ." buttons {"Quit", "Enter Password"}
if main = {button returned:"Enter Password"} or trueaftermain = "1" then
set results to paragraphs 2 thru -1 of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'")
set my_list to results
set AppleScript's text item delimiters to ", "
set list_2_string to my_list as text
set main to display dialog my_list
set wpass to choose from list {my_list} with title "Pick The Wifi" with prompt "Choose WPA2" OK button name "Choose" cancel button name "Cancel" default items {"quit"}
end if
答案 0 :(得分:0)
你的代码太复杂了。
results
已经是您期望的列表。
set results to paragraphs of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'")
set wpass to choose from list results with title "Pick The Wifi" with prompt "Choose WPA2" OK button name "Choose"
请注意wpass
也是一个列表,如果用户按取消
false
如果您使用text item delimiters
,请确保稍后重置分隔符以避免意外行为。