| 1 |
property bochs_path : "Contents/MacOS/bochs" |
| 2 |
property bochs_app : "" |
| 3 |
|
| 4 |
on run |
| 5 |
tell application "Finder" to get container of (path to me) as string |
| 6 |
set script_path to POSIX path of result |
| 7 |
|
| 8 |
-- Locate bochs |
| 9 |
set bochs_alias to findBochs() |
| 10 |
|
| 11 |
-- Tell Terminal to run bochs from the command line |
| 12 |
--Use the script's directory as the current directory |
| 13 |
tell application "Terminal" |
| 14 |
activate |
| 15 |
do script "cd '" & script_path & "';exec '" & (POSIX path of bochs_app) & bochs_path&"'" |
| 16 |
-- Wait for Terminal to change the name first, then change it to ours |
| 17 |
delay 1 |
| 18 |
set AppleScript's text item delimiters to "/" |
| 19 |
set the text_item_list to every text item of the script_path |
| 20 |
set AppleScript's text item delimiters to "" |
| 21 |
|
| 22 |
|
| 23 |
set next_to_last to ((count of text_item_list) - 1) |
| 24 |
set the folder_name to item next_to_last of text_item_list |
| 25 |
set name of front window to "Running bochs in ../" & folder_name & "/" |
| 26 |
end tell |
| 27 |
end run |
| 28 |
|
| 29 |
-- Taken from examples at http://www.applescriptsourcebook.com/tips/findlibrary.html |
| 30 |
to Hunt for itemName at folderList |
| 31 |
--Returns path to itemName as string, or empty string if not found |
| 32 |
repeat with aFolder in folderList |
| 33 |
try |
| 34 |
if class of aFolder is constant then |
| 35 |
return alias ((path to aFolder as string) & itemName) as string |
| 36 |
else if folder of (info for alias aFolder) then |
| 37 |
return alias (aFolder & itemName) as string |
| 38 |
end if |
| 39 |
on error number -43 --item not there, go to next folder |
| 40 |
end try |
| 41 |
end repeat |
| 42 |
return "" --return empty string if item not found |
| 43 |
end Hunt |
| 44 |
|
| 45 |
on findBochs() |
| 46 |
try |
| 47 |
if bochs_app is "" then error number -43 |
| 48 |
return alias bochs_app |
| 49 |
on error number -43 |
| 50 |
-- bochs_app no good, go hunting |
| 51 |
try |
| 52 |
tell application "Finder" to get container of (path to me) as string |
| 53 |
set this_dir_alias to alias result |
| 54 |
tell application "Finder" to get container of (this_dir_alias) as string |
| 55 |
set one_up_dir_alias to alias result |
| 56 |
set TheUsualPlaces to {this_dir_alias as string, one_up_dir_alias as string} |
| 57 |
Hunt for "bochs.app" at TheUsualPlaces |
| 58 |
set result_alias to result |
| 59 |
if result_alias is "" then error number -43 |
| 60 |
set bochs_app to result_alias as string |
| 61 |
return result_alias |
| 62 |
on error number -43 |
| 63 |
--Give up seeking, Ask the user |
| 64 |
choose application with prompt "Please locate Bochs:" as alias |
| 65 |
set result_alias to result |
| 66 |
set bochs_app to result_alias as string |
| 67 |
return result_alias |
| 68 |
end try |
| 69 |
end try |
| 70 |
end findBochs |