-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_executable_fixer.rb
executable file
·55 lines (45 loc) · 1.3 KB
/
app_executable_fixer.rb
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
#!/usr/bin/ruby
# By Sven Pachnit (a BMonkey)
# www.bmonkeys.net
# Code License: http://opensource.org/licenses/MIT
# Icon License: http://www.iconfinder.com/icondetails/24775/128/application_executable_script_x_icon
# flush stdout after each output
STDOUT.sync = true
def pexit message, delay = 5
puts message
sleep delay
exit 0
end
# our file
file = ARGV * " "
# probably initial start
exit 0 if !file || file.empty?
# check if file is an OS X application
if !(file.end_with?(".app") || file.end_with?(".app/"))
pexit "Please drop an OS X application here"
end
# search executable
puts "Checking application"
choices = Dir.glob("#{file}/Contents/MacOS/*").select { |f| File.file?(f) }
exechoices = choices.select { |f| File.executable?(f) }
if choices.count != 1 && (exechoices.empty? || exechoices.count > 1)
pexit "Can't determine executable!"
end
if exechoices.count == 1
pexit "Application seems intact, nothing to do"
end
if exechoices.count == 0 && choices.count == 1
# fix the file
begin
if File.chmod(0777, choices.first) == 1
pexit "Application fixed! Have fun!"
else
raise StandardError, "File wasn't changed!"
end
rescue StandardError => e
puts "Can't change file permissions!"
sleep 3
pexit e.message
end
end
pexit "unhandled case (blame the developer)"