-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDropEFI.applescript
More file actions
105 lines (91 loc) · 3.86 KB
/
DropEFI.applescript
File metadata and controls
105 lines (91 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--
-- DropEFI.applescript Created by chris1111 on 1-5-24.
-- Base on (https://www.sonsothunder.com/devres/revolution/tutorials/StatusMenu.html).
--
property NSBundle : class "NSBundle"
property NSStatusItem : class "NSStatusItem"
property NSString : class "NSString"
property NSImage : class "NSImage"
property NSStatusBar : class "NSStatusBar"
script MenuletAppDelegate
property parent : class "NSObject"
property setup : false
property myMenu : missing value
property theView : missing value
property textField : missing value
property spinner : missing value
property statusItem : missing value
property AppletIcon : missing value
property AssistantIcon : missing value
on doMenuStuff:sender -- Mount EFI using DropEFI
activate me
set source to quoted form of POSIX path of (path to resource "DropEFI.app")
do shell script "open " & source
end doMenuStuff:
on doSomething:sender -- Unmount EFI
startSpinner()
set source to quoted form of POSIX path of (path to resource "Unmount")
set Unmountaif to quoted form of POSIX path of (path to resource "Unmountaif")
set Notification to quoted form of POSIX path of (path to resource "Notification")
performSelector_withObject_afterDelay_("stopSpinner", missing value, 2.5)
delay 2.5
do shell script source with administrator privileges
do shell script Unmountaif
do shell script Notification
end doSomething:
on awakeFromNib()
set bundle to NSBundle's mainBundle()
set AppletIcon to NSImage's alloc's initWithContentsOfFile:(bundle's pathForResource:"Applet" ofType:"png")
set AssistantIcon to NSImage's alloc's initWithContentsOfFile:(bundle's pathForResource:"Assistant" ofType:"png")
set statusItem to NSStatusBar's systemStatusBar's statusItemWithLength:-1 --
statusItem's setImage:AppletIcon
statusItem's setAlternateImage:AssistantIcon
statusItem's setMenu:myMenu
statusItem's setToolTip:"StatusMenu"
statusItem's setHighlightMode:true
end awakeFromNib
on applicationWillFinishLaunching:aNotification
end applicationWillFinishLaunching:
on applicationShouldTerminate:sender
return current application's NSTerminateNow
end applicationShouldTerminate:
on startSpinner()
setupTitle()
statusItem's setView:theView
spinner's startAnimation:me
end startSpinner
on stopSpinner()
spinner's stopAnimation:me
statusItem's setView:(missing value)
statusItem's setImage:AppletIcon
statusItem's setAlternateImage:AssistantIcon
end stopSpinner
on setupTitle()
if setup then return
set menuBarFont to current application's NSFont's menuBarFontOfSize:12
set attributes to current application's NSDictionary's dictionaryWithDictionary:{NSFontAttributeName:menuBarFont, NSParagraphStyleAttributeName:(current application's NSParagraphStyle's defaultParagraphStyle)}
set theTitle to current application's NSString's stringWithString:" Unmount"
set titleWidth to ((width of ((theTitle's sizeWithAttributes:attributes) as record)) as integer) + 12
set textField to current application's NSTextField's alloc's initWithFrame:{{0, 0}, {titleWidth, 22}}
tell textField # set up textField properties
setFont_(menuBarFont)
setStringValue_(theTitle)
setDrawsBackground_(false)
setBezeled_(false)
end tell
set spinner to current application's NSProgressIndicator's alloc's initWithFrame:{{0, 0}, {16, 16}}
tell spinner # set up spinner properties
setControlSize_(current application's NSSmallControlSize)
setStyle_(current application's NSProgressIndicatorSpinningStyle)
setUsesThreadedAnimation_(true)
end tell
set theView to current application's NSView's alloc's initWithFrame:{{0, 0}, {22 + titleWidth, 22}}
tell theView # add everything to the view and adjust locations
addSubview_(textField)
textField's setFrameOrigin:{22.0, -2.0}
addSubview_(spinner)
spinner's setFrameOrigin:{5.0, 4.0}
end tell
set setup to true
end setupTitle
end script