【发布时间】:2019-08-13 20:55:28
【问题描述】:
所以我在一个更大的 bash 脚本中嵌入了一个 AppleScript,我希望打开对话框让用户向他们提问,接受这些变量,然后将它们传递给 bash 脚本以运行更多命令。但是,它似乎没有将变量传递到我的 bash 脚本中,而是处于一个恒定循环中。由于我将使用的交付方式,我需要这样做。我知道我可以使用读取命令完成相同的结果。
我尝试查找此问题并找到了很多答案,但要么没有工作,要么他们正在使用比我需要的更大的环境。这个链接https://discussions.apple.com/thread/2512634 是我发现的最接近我正在做的事情,我几乎一字不差地拥有它,但它仍然没有通过它们并且处于不断循环中
#! /bin/sh #Asset.sh
NUM="$1" # << this is supposed to be varible FROM applescript
if [[ "$Model" = "MacBook Pro" ]]; then #do not mind my varibles here
osascript -e 'tell me to activate
display dialog "We need to ask you a few questions"
property FloatNumber : ""
display dialog "Please enter a floater number:" default answer FloatNumber
set the FloatNumber to text returned of the result
do shell script ("/Users/administrator/Downloads/Asset.sh " & FloatNumber)'
if [[ "$SSD_check" = "Yes" ]]; then #do not mind my varibles here
scutil --set HostName CAD$NUM;
scutil --set LocalHostName CAD$NUM;
scutil --set ComputerName CAD$NUM;
dscacheutil -flushcache;
您可能已经知道,如果我将笔记本电脑命名为 CAD##,我希望将变量从 AppleScript 传递到更大的 bash 脚本中,而不是让 AppleScript 陷入循环。
基本上,我正在尝试将我在“浮动/贷方”笔记本电脑和用户笔记本电脑上运行的所有脚本捆绑在一起,并通过我们使用的 JAMF 第三方分销商部署该脚本,该分销商有一个名为 Self Service 的应用程序。我希望能够运行这个脚本和这个主脚本基本上重命名,添加远程桌面字段,创建我们使用的某些用户目录,等等等等......正如我提到的使用 Applescript 对我来说是全新的bash 不在的地方。我宁愿将它捆绑在一个“主”脚本中。我真正遇到的唯一问题是applescript
编辑添加脚本:
#!/bin/sh
SIPs=$(csrutil status | awk -F ": " '{print $2}')
lastUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
ecSIGN=$(/Applications/Enterprise\ Connect.app/Contents/SharedSupport/eccl -p signedInStatus | awk -F ": " '{print $2}')
ecNAME=$(/Applications/Enterprise\ Connect.app/Contents/SharedSupport/eccl -a name | awk -F ": " '{print $2}')
ecDEPT=$(/Applications/Enterprise\ Connect.app/Contents/SharedSupport/eccl -a department | awk -F ": " '{print $2}')
ecTITLE=$(/Applications/Enterprise\ Connect.app/Contents/SharedSupport/eccl -a title | awk -F ": " '{print $2}')
L3_cache=$(system_profiler SPHardwareDataType | grep L3 | sed -e 's/^[ \t]*//')
Model=$(system_profiler SPHardwareDataType | grep "Model Name" | awk -F ": " '{print $2}' | sed -e 's/^[ \t]*//')
SSD_check=$(diskutil info disk0 | grep "Solid State" | awk -F ": " '{print $2}' | sed -e 's/^[ \t]*//')
PUBLIC_MOUNT=$(mount | awk '$3 == "/Volumes/Public" {print $3}')
DIALOG=$(osascript -e 'display dialog "Please enter a floater number :" default answer "" with title "Just a Few Questions"
set the FloatNumber to text returned of the result
return FloatNumber')
NUM=$(echo $DIALOG)
echo "Checking to see if csrutil is enabled";
if [[ "$SIPs" = "enabled." ]]; then
echo "csrutil is enabled. Please turn it off";
exit 1
else {
echo "About to run some scripts...";
echo "Setting ARDFields and setting computer name and assigning it in JSS";
if [[ "$lastUser" = "administrator" ]] && [[ "$Model" = "MacBook Pro" ]]; then
$DIALOG
if [[ "$SSD_check" = "Yes" ]]; then
scutil --set HostName CAD$NUM;
scutil --set LocalHostName CAD$NUM;
scutil --set ComputerName CAD$NUM;
dscacheutil -flushcache;
else {
scutil --set HostName Floater$NUM;
scutil --set LocalHostName Floater$NUM;
scutil --set ComputerName Floater$NUM;
dscacheutil -flushcache;
}
fi
else {
scutil --set HostName NewUser$NUM;
scutil --set LocalHostName NewUser$NUM;
scutil --set ComputerName NewUser$NUM;
dscacheutil -flushcache;
}
fi
}
fi
最终结果!!
【问题讨论】:
标签: bash applescript