-
Notifications
You must be signed in to change notification settings - Fork 2
/
ToolBox.rb
73 lines (62 loc) · 1.52 KB
/
ToolBox.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$MyDir = File.expand_path File.dirname(__FILE__)
require File.join $MyDir, 'GrowlInterface'
$Se = Appscript.app.by_name("System Events")
$KeyLeft=123
$KeyReturn=36
$KeyDelete=51
def timeThis(method=nil, *args)
beginning_time = Time.now
if block_given?
yield
else
self.send(method, args)
end
end_time = Time.now
puts "Time elapsed #{(end_time - beginning_time).to_i} sec"
end
def uiManip (method=nil, *args)
n 'Hands off!'
if block_given?
yield
else
self.send(method, args)
end
n 'At ease'
end
def sleepp sec
print "sleepp "+sec.to_s
sleep sec
print " done\n"
end
def getAppId path
OSAX.osax.info_for(MacTypes::Alias.path(path))[:bundle_identifier]
end
def selectInFileChooser inputPath
srcDirName, srcFileName, extention = breakUpPath inputPath
$Se.keystroke('g', :using => [:command_down, :shift_down])
sleep(0.1)
$Se.key_code($KeyDelete)
sleep(0.1)
srcDirName.reverse.each_char do |c|
$Se.keystroke c
sleep 0.01
$Se.key_code($KeyLeft)
sleep 0.01
end
$Se.key_code($KeyReturn)
sleep 5
$Se.keystroke(srcFileName+'.'+extention)
sleep 3
$Se.key_code($KeyReturn)
end
def exceptionToS e
"\n-------------\nError: "+ e.message.strip + "\n" + e.backtrace.join("\n")+"\n-----\n"
end
def breakUpPath inputPath
lastSlash = inputPath.rindex("/")
lastPoint = inputPath.rindex(".")
srcDirName=inputPath[0..lastSlash]
srcFileName=inputPath[lastSlash+1..lastPoint-1]
extention=inputPath[lastPoint+1..inputPath.length]
[srcDirName, srcFileName, extention]
end