Class: Kscript::KkMacOptimizeUtils
- Inherits:
-
Base
- Object
- Base
- Kscript::KkMacOptimizeUtils
show all
- Defined in:
- lib/kscript/plugins/kk_mac_optimize_utils.rb
Instance Attribute Summary
Attributes inherited from Base
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#human_output?, inherited, #with_error_handling
Constructor Details
Returns a new instance of KkMacOptimizeUtils.
12
13
14
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 12
def initialize(*args, **opts)
super
end
|
Class Method Details
.arguments ⇒ Object
72
73
74
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 72
def self.arguments
''
end
|
.author ⇒ Object
84
85
86
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 84
def self.author
'kk'
end
|
.description ⇒ Object
88
89
90
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 88
def self.description
'Optimize macOS system performance.'
end
|
.group ⇒ Object
80
81
82
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 80
def self.group
'macos'
end
|
.usage ⇒ Object
76
77
78
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 76
def self.usage
'kscript mac_optimize'
end
|
Instance Method Details
#optimize_all ⇒ Object
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
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 26
def optimize_all
logger.kinfo('๐ง Starting macOS system optimization...')
orb_pid = `pgrep -f "OrbStack Helper"`.strip
unless orb_pid.empty?
logger.kinfo("๐ Found OrbStack Helper (PID: #{orb_pid}), lowering priority...")
system("sudo renice +15 #{orb_pid}")
logger.kinfo('โ
Priority lowered')
end
apps = ['Telegram', 'Google Chrome']
apps.each do |app|
if system("pgrep -x \"#{app}\" > /dev/null")
logger.kinfo("๐ Closing #{app}...")
system("osascript -e 'tell application \"#{app}\" to quit'")
end
end
logger.kinfo('๐งน Purging memory cache...')
system('sudo purge')
logger.kinfo('โ
Memory cache purged')
macos_version = `sw_vers -productVersion`.strip
if macos_version.split('.').first.to_i >= 12
logger.kinfo('โก Enabling Low Power Mode...')
system('pmset -a lowpowermode 1')
logger.kinfo('โ
Low Power Mode enabled')
else
logger.kwarn("โ ๏ธ Your macOS version (#{macos_version}) does not support Low Power Mode, skipping.")
end
if system('which osx-cpu-temp > /dev/null')
temp = `osx-cpu-temp`.strip
logger.kinfo("๐ก Current CPU Temperature: #{temp}")
else
logger.kinfo("โน๏ธ Install 'osx-cpu-temp' to see CPU temperature (brew install osx-cpu-temp)")
end
logger.kinfo('๐ Optimization complete. Monitor your system for improvements!')
end
|
#run(*args, **_opts) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/kscript/plugins/kk_mac_optimize_utils.rb', line 16
def run(*args, **_opts)
with_error_handling do
if %w[help --help -h].include?(args[0]&.to_s)
logger.kwarn("Usage: #{self.class.usage}")
else
optimize_all
end
end
end
|