0

我创建了一个从雪豹引导到狮子的苹果脚本,但是 bless 命令失败了。这是命令:

do shell script "bless -mount /Volumes/bootdrive/ -legacy -setBoot -nextonly" password "mypassword" with administrator privileges

重新启动时,出现“无可启动设备”错误的黑屏。我已经以 root 身份(而不是作为 applescript)直接在终端中运行该命令,并得到了相同的结果。是的,我已经三重检查了我使用的磁盘路径是否正确并且可以引导。

知道问题可能是什么吗?

4

2 回答 2

0

我没有合适的设置来测试,但这个-legacy选项对我来说看起来很可疑。根据手册页,它用于支持基于 BIOS 的操作系统,而 OS X 不支持。尝试删除-legacy,看看它是否效果更好。

于 2013-04-11T20:27:00.853 回答
0

工作解决方案

SIP 是我在 Big Sur 上遇到的第一个问题。关闭它看起来是个坏主意。第二个问题是目标卷列表项没有操作。这使得无法通过点击或“点击”功能点击它们,这可能是因为 Big Sur 上有一些新的额外保护。由于新的 MacOS 限制,使用 AST 和其他脚本单击也不起作用。我发现的唯一方法是使用 python click(但这会在脚本选择目标卷时导致轻微延迟)。

所以这里是一个全自动切换:

property targetVolume : "BOOTCAMP" # find name of required volume inside System Preference > Startup Disk
property passwordValue : "yourSystemPassword" # Can be empty

tell application "System Events"
    tell application "System Preferences"
        set current pane to pane id "com.apple.preference.startupdisk"
        activate
    end tell
    tell application process "System Preferences"
        tell window "Startup Disk"
            set volumePosition to {0, 0}
            set lockFound to false
            
            # Check if auth required
            set authButtonText to "Click the lock to make changes."
            if exists button authButtonText then
                click button authButtonText
                
                # Wait for auth modal
                set unlockButtonText to "Unlock"
                repeat
                    if (exists sheet 1) and (exists button unlockButtonText of sheet 1) then exit repeat
                end repeat
                
                # Autofill password if setted
                if passwordValue is not equal to "" then
                    set value of text field 1 of sheet 1 to passwordValue
                    click button unlockButtonText of sheet 1
                end if
                
                # Wait for auth success
                repeat
                    if exists button "Click the lock to prevent further changes." then exit repeat
                end repeat
            end if
            
            # Wait until loading volumes list
            repeat
                if exists group 1 of list 1 of scroll area 1 then exit repeat
            end repeat
            
            # Click on target volume (posible a slight delay because of shell script executing)
            repeat with m in (UI element of list 1 of scroll area 1)
                if (value of first static text of m = targetVolume) then
                    tell static text targetVolume of m
                        set volumePosition to position
                    end tell
                end if
            end repeat
            set volumePositionX to item 1 of volumePosition
            set volumePositionY to item 2 of volumePosition
            my customClick(volumePositionX, volumePositionY)
            
            click button "Restart…"
            
            # Wait for restart modal appears
            repeat
                if (exists sheet 1) and (exists value of first static text of sheet 1) then exit repeat
            end repeat
            
            click button "Restart" of sheet 1
        end tell
    end tell
end tell

# shell script to make click work on target volume
on customClick(x, y)
    do shell script " 

/usr/bin/python <<END

import sys

import time

from Quartz.CoreGraphics import * 

def mouseEvent(type, posx, posy):

          theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)

          CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):

          mouseEvent(kCGEventMouseMoved, posx,posy);

def mouseclick(posx,posy):

          mouseEvent(kCGEventLeftMouseDown, posx,posy);

          mouseEvent(kCGEventLeftMouseUp, posx,posy);

ourEvent = CGEventCreate(None); 

currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position

mouseclick(" & x & "," & y & ");

mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position

END"
end customClick

on simpleEncryption(_str)
    set x to id of _str
    repeat with c in x
        set contents of c to c + 100
    end repeat
    return string id x
end simpleEncryption

on simpleDecryption(_str)
    set x to id of _str
    repeat with c in x
        set contents of c to c - 100
    end repeat
    return string id x
end simpleDecryption

您只需要更改两个属性targetVolumepasswordValue。密码可以为空,在这种情况下,您可以手动提供。然后只需复制此脚本,将其粘贴到脚本编辑器并通过文件 -> 导出 -> 文件格式 - 应用程序导出,选择仅运行 -> 保存。您可以对您拥有的所有系统执行相同的过程,例如 Big Sur 1、Big Sur 2、Bootcamp。

于 2021-10-18T13:50:07.127 回答