0

Snow Leopard から Lion にブートするための AppleScript を作成しましたが、bless コマンドが失敗します。コマンドは次のとおりです。

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

再起動すると、「起動可能なデバイスがありません」というエラーが表示された黒い画面が表示されます。ターミナルで (applescript としてではなく) root としてコマンドを直接実行したところ、同じ結果が得られました。はい、使用しているディスク パスが正しく、起動可能であることを 3 回確認しました。

問題が何であるか考えていますか?

4

2 に答える 2

0

ワーキングソリューション

Big Sur で最初に遭遇した問題は SIP でした。それをオフにするのは悪い考えのように見えます。2 つ目の問題は、ターゲット ボリュームのリスト アイテムにアクションがないことです。おそらく、Big Sur にいくつかの新しい保護が追加されたため、クリックまたは「クリック」機能を使用してそれらをクリックすることができなくなります。新しい MacOS の制限により、AST やその他のスクリプトでのクリックも機能しません。私が見つけた唯一の方法は、pythonクリックを使用することです(ただし、これにより、スクリプトがターゲットボリュームを選択するときにわずかな遅延が発生します)。

したがって、完全に自動化された切り替えは次のとおりです。

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の 2 つのプロパティを変更するだけです。パスワードは空にすることができ、その場合は手動で入力できます。次に、このスクリプトをコピーしてスクリプト エディターに貼り付け、[ファイル] -> [エクスポート] -> [ファイル形式] - [アプリケーション] でエクスポートし、[実行のみ] -> [保存] を選択します。Big Sur 1、Big Sur 2、Bootcamp など、すべてのシステムで同じプロセスを実行できます。

于 2021-10-18T13:50:07.127 に答える