rb-scpt 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rb-scpt-1.0.1.gem +0 -0
- data/extconf.rb +12 -12
- data/rb-scpt.gemspec +10 -10
- data/sample/AB_export_vcard.rb +16 -16
- data/sample/AB_list_people_with_emails.rb +4 -4
- data/sample/Add_iCal_event.rb +12 -12
- data/sample/Create_daily_iCal_todos.rb +28 -28
- data/sample/Export_Address_Book_phone_numbers.rb +52 -52
- data/sample/Hello_world.rb +10 -10
- data/sample/List_iTunes_playlist_names.rb +3 -3
- data/sample/Make_Mail_message.rb +24 -24
- data/sample/Open_file_in_TextEdit.rb +5 -5
- data/sample/Organize_Mail_messages.rb +46 -46
- data/sample/Print_folder_tree.rb +5 -5
- data/sample/Select_all_HTML_files.rb +6 -6
- data/sample/Set_iChat_status.rb +12 -12
- data/sample/Simple_Finder_GUI_Scripting.rb +6 -6
- data/sample/Stagger_Finder_windows.rb +9 -9
- data/sample/TextEdit_demo.rb +71 -71
- data/sample/iTunes_top40_to_html.rb +28 -30
- data/src/SendThreadSafe.c +293 -293
- data/src/SendThreadSafe.h +108 -108
- data/src/lib/_aem/aemreference.rb +997 -998
- data/src/lib/_aem/codecs.rb +609 -610
- data/src/lib/_aem/connect.rb +197 -197
- data/src/lib/_aem/encodingsupport.rb +67 -67
- data/src/lib/_aem/findapp.rb +75 -75
- data/src/lib/_aem/mactypes.rb +241 -242
- data/src/lib/_aem/send.rb +268 -268
- data/src/lib/_aem/typewrappers.rb +52 -52
- data/src/lib/_appscript/defaultterminology.rb +266 -266
- data/src/lib/_appscript/referencerenderer.rb +230 -233
- data/src/lib/_appscript/reservedkeywords.rb +106 -106
- data/src/lib/_appscript/safeobject.rb +125 -125
- data/src/lib/_appscript/terminology.rb +448 -449
- data/src/lib/aem.rb +238 -238
- data/src/lib/kae.rb +1487 -1487
- data/src/lib/osax.rb +647 -647
- data/src/lib/rb-scpt.rb +1065 -1065
- data/src/rbae.c +595 -595
- data/test/test_aemreference.rb +104 -107
- data/test/test_appscriptcommands.rb +131 -134
- data/test/test_appscriptreference.rb +96 -99
- data/test/test_codecs.rb +166 -168
- data/test/test_findapp.rb +13 -16
- data/test/test_mactypes.rb +70 -72
- data/test/test_osax.rb +46 -48
- data/test/testall.sh +4 -4
- metadata +8 -7
@@ -5,9 +5,9 @@
|
|
5
5
|
# Note: if using the appscript gem, rubygems must be required first:
|
6
6
|
begin; require 'rubygems'; rescue LoadError; end
|
7
7
|
|
8
|
-
require "appscript"
|
9
|
-
include Appscript
|
8
|
+
require "appscript"
|
9
|
+
include Appscript
|
10
10
|
|
11
|
-
te = app('TextEdit')
|
12
|
-
te.activate
|
13
|
-
te.open(MacTypes::Alias.path('/Users/USERNAME/ReadMe.txt'))
|
11
|
+
te = app('TextEdit')
|
12
|
+
te.activate
|
13
|
+
te.open(MacTypes::Alias.path('/Users/USERNAME/ReadMe.txt'))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Set up a Mail mailbox folder for organising incoming emails from a
|
3
|
+
# Set up a Mail mailbox folder for organising incoming emails from a
|
4
4
|
# particular sender.
|
5
5
|
#
|
6
6
|
# Based on an AppleScript by Michelle Steiner.
|
@@ -14,48 +14,48 @@
|
|
14
14
|
# Note: if using the appscript gem, rubygems must be required first:
|
15
15
|
begin; require 'rubygems'; rescue LoadError; end
|
16
16
|
|
17
|
-
require "appscript"
|
18
|
-
include Appscript
|
19
|
-
|
20
|
-
mail = app('Mail')
|
21
|
-
|
22
|
-
# get the current selection in Mail and make sure it's an email message
|
23
|
-
selection = mail.selection.get
|
24
|
-
|
25
|
-
if selection == [] or selection[0].class_.get != :message
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
# get a reference to the first selected message
|
31
|
-
msg = selection[0]
|
32
|
-
|
33
|
-
recipient = msg.to_recipients[1]
|
34
|
-
address = recipient.address.get
|
35
|
-
|
36
|
-
# determine the new mailbox's name based on the sender's name/address
|
37
|
-
if recipient.name.exists
|
38
|
-
|
39
|
-
else
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# make a new mailbox if one doesn't already exist
|
44
|
-
if not mail.mailboxes[folder_name].exists
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
# make a new mail rule to move list messages to the mailbox
|
50
|
-
if not mail.rules[folder_name].exists
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
17
|
+
require "appscript"
|
18
|
+
include Appscript
|
19
|
+
|
20
|
+
mail = app('Mail')
|
21
|
+
|
22
|
+
# get the current selection in Mail and make sure it's an email message
|
23
|
+
selection = mail.selection.get
|
24
|
+
|
25
|
+
if selection == [] or selection[0].class_.get != :message
|
26
|
+
puts "Please select a message and try again."
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
# get a reference to the first selected message
|
31
|
+
msg = selection[0]
|
32
|
+
|
33
|
+
recipient = msg.to_recipients[1]
|
34
|
+
address = recipient.address.get
|
35
|
+
|
36
|
+
# determine the new mailbox's name based on the sender's name/address
|
37
|
+
if recipient.name.exists
|
38
|
+
folder_name = recipient.name.get
|
39
|
+
else
|
40
|
+
folder_name = /^[^@]*/.match(address)[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
# make a new mailbox if one doesn't already exist
|
44
|
+
if not mail.mailboxes[folder_name].exists
|
45
|
+
mail.mailboxes.end.make(:new=>:mailbox, :with_properties=>{
|
46
|
+
:name=>folder_name})
|
47
|
+
end
|
48
|
+
|
49
|
+
# make a new mail rule to move list messages to the mailbox
|
50
|
+
if not mail.rules[folder_name].exists
|
51
|
+
new_rule = mail.rules[1].after.make(:new=>:rule, :with_properties=>{
|
52
|
+
:name=>folder_name,
|
53
|
+
:should_move_message=>true,
|
54
|
+
:move_message=>app.mailboxes[folder_name],
|
55
|
+
:stop_evaluating_rules=>true})
|
56
|
+
new_rule.make(:new=>:rule_condition, :with_properties=>{
|
57
|
+
:expression=>address,
|
58
|
+
:rule_type=>:to_header,
|
59
|
+
:qualifier=>:does_contain_value})
|
60
|
+
new_rule.enabled.set(true)
|
61
|
+
end
|
data/sample/Print_folder_tree.rb
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
# Note: if using the appscript gem, rubygems must be required first:
|
6
6
|
begin; require 'rubygems'; rescue LoadError; end
|
7
7
|
|
8
|
-
require "appscript"
|
9
|
-
include Appscript
|
8
|
+
require "appscript"
|
9
|
+
include Appscript
|
10
10
|
|
11
|
-
def print_folder_tree(folder, indent='')
|
11
|
+
def print_folder_tree(folder, indent='')
|
12
12
|
puts indent + folder.name.get
|
13
13
|
folder.folders.get.each { |folder| print_folder_tree(folder, indent + "\t") }
|
14
|
-
end
|
14
|
+
end
|
15
15
|
|
16
|
-
print_folder_tree(app('Finder').home.folders['Documents'])
|
16
|
+
print_folder_tree(app('Finder').home.folders['Documents'])
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# Note: if using the appscript gem, rubygems must be required first:
|
6
6
|
begin; require 'rubygems'; rescue LoadError; end
|
7
7
|
|
8
|
-
require "appscript"
|
9
|
-
include Appscript
|
8
|
+
require "appscript"
|
9
|
+
include Appscript
|
10
10
|
|
11
|
-
finder = app('Finder')
|
12
|
-
finder.activate
|
13
|
-
folder = finder.Finder_windows[1].target.get
|
14
|
-
folder.files[its.name_extension.is_in(['htm', 'html'])].select
|
11
|
+
finder = app('Finder')
|
12
|
+
finder.activate
|
13
|
+
folder = finder.Finder_windows[1].target.get
|
14
|
+
folder.files[its.name_extension.is_in(['htm', 'html'])].select
|
data/sample/Set_iChat_status.rb
CHANGED
@@ -9,16 +9,16 @@
|
|
9
9
|
# Note: if using the appscript gem, rubygems must be required first:
|
10
10
|
begin; require 'rubygems'; rescue LoadError; end
|
11
11
|
|
12
|
-
require "appscript"
|
13
|
-
include Appscript
|
12
|
+
require "appscript"
|
13
|
+
include Appscript
|
14
14
|
|
15
|
-
begin
|
16
|
-
|
17
|
-
rescue CommandError => e
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
app("iChat").status_message.set(track_name)
|
15
|
+
begin
|
16
|
+
track_name = app("iTunes").current_track.name.get
|
17
|
+
rescue CommandError => e
|
18
|
+
if e.to_i == -1728 # Can't get reference.
|
19
|
+
track_name = 'No track selected.'
|
20
|
+
else
|
21
|
+
raise
|
22
|
+
end
|
23
|
+
end
|
24
|
+
app("iChat").status_message.set(track_name)
|
@@ -8,11 +8,11 @@
|
|
8
8
|
# Note: if using the appscript gem, rubygems must be required first:
|
9
9
|
begin; require 'rubygems'; rescue LoadError; end
|
10
10
|
|
11
|
-
require 'appscript'
|
12
|
-
include Appscript
|
11
|
+
require 'appscript'
|
12
|
+
include Appscript
|
13
13
|
|
14
|
-
se = app('System Events')
|
14
|
+
se = app('System Events')
|
15
15
|
|
16
|
-
app('Finder').activate
|
17
|
-
se.keystroke('n', :using=>[:command_down, :option_down])
|
18
|
-
se.keystroke('ruby')
|
16
|
+
app('Finder').activate
|
17
|
+
se.keystroke('n', :using=>[:command_down, :option_down])
|
18
|
+
se.keystroke('ruby')
|
@@ -7,19 +7,19 @@
|
|
7
7
|
# Note: if using the appscript gem, rubygems must be required first:
|
8
8
|
begin; require 'rubygems'; rescue LoadError; end
|
9
9
|
|
10
|
-
require "appscript"
|
11
|
-
include Appscript
|
10
|
+
require "appscript"
|
11
|
+
include Appscript
|
12
12
|
|
13
|
-
x, y = 0, 44
|
14
|
-
offset = 22
|
13
|
+
x, y = 0, 44
|
14
|
+
offset = 22
|
15
15
|
|
16
|
-
# Get list of window references, ignoring any minimised windows
|
17
|
-
window_list = app('Finder').windows[its.collapsed.not].get
|
16
|
+
# Get list of window references, ignoring any minimised windows
|
17
|
+
window_list = app('Finder').windows[its.collapsed.not].get
|
18
18
|
|
19
|
-
# Move windows while preserving their original sizes
|
20
|
-
window_list.reverse.each do |window|
|
19
|
+
# Move windows while preserving their original sizes
|
20
|
+
window_list.reverse.each do |window|
|
21
21
|
x1, y1, x2, y2 = window.bounds.get
|
22
22
|
window.bounds.set([x, y, x2 - x1 + x, y2 - y1 + y])
|
23
23
|
x += offset
|
24
24
|
y += offset
|
25
|
-
end
|
25
|
+
end
|
data/sample/TextEdit_demo.rb
CHANGED
@@ -5,126 +5,126 @@
|
|
5
5
|
# Note: if using the appscript gem, rubygems must be required first:
|
6
6
|
begin; require 'rubygems'; rescue LoadError; end
|
7
7
|
|
8
|
-
require "appscript"
|
9
|
-
include Appscript
|
8
|
+
require "appscript"
|
9
|
+
include Appscript
|
10
10
|
|
11
|
-
textedit = app('TextEdit') # get an application object for TextEdit
|
11
|
+
textedit = app('TextEdit') # get an application object for TextEdit
|
12
12
|
|
13
13
|
|
14
|
-
# tell application "TextEdit" to activate
|
15
|
-
textedit.activate
|
14
|
+
# tell application "TextEdit" to activate
|
15
|
+
textedit.activate
|
16
16
|
|
17
17
|
|
18
|
-
# tell application "TextEdit" to make new document at end of documents
|
19
|
-
textedit.documents.end.make(:new => :document)
|
18
|
+
# tell application "TextEdit" to make new document at end of documents
|
19
|
+
textedit.documents.end.make(:new => :document)
|
20
20
|
|
21
21
|
|
22
|
-
# tell application "TextEdit" to set text of document 1 to "Hello World\n"
|
23
|
-
textedit.documents[1].text.set('Hello World\n')
|
22
|
+
# tell application "TextEdit" to set text of document 1 to "Hello World\n"
|
23
|
+
textedit.documents[1].text.set('Hello World\n')
|
24
24
|
|
25
25
|
|
26
|
-
# tell application "TextEdit" to get a reference to every window
|
27
|
-
p textedit.windows
|
26
|
+
# tell application "TextEdit" to get a reference to every window
|
27
|
+
p textedit.windows
|
28
28
|
|
29
29
|
|
30
|
-
# tell application "TextEdit" to get a reference to document 1
|
31
|
-
p textedit.documents
|
30
|
+
# tell application "TextEdit" to get a reference to document 1
|
31
|
+
p textedit.documents
|
32
32
|
|
33
33
|
|
34
|
-
# tell application "TextEdit" to get every document
|
35
|
-
p textedit.documents.get
|
34
|
+
# tell application "TextEdit" to get every document
|
35
|
+
p textedit.documents.get
|
36
36
|
|
37
37
|
|
38
|
-
# tell application "TextEdit" to get a reference to document 1
|
39
|
-
p textedit.documents[1]
|
38
|
+
# tell application "TextEdit" to get a reference to document 1
|
39
|
+
p textedit.documents[1]
|
40
40
|
|
41
41
|
|
42
|
-
# tell application "TextEdit" to get document 1
|
43
|
-
p textedit.documents[1].get
|
42
|
+
# tell application "TextEdit" to get document 1
|
43
|
+
p textedit.documents[1].get
|
44
44
|
|
45
45
|
|
46
|
-
# tell application "TextEdit" to get window id 3210
|
47
|
-
# p textedit.windows.ID(3210).get
|
46
|
+
# tell application "TextEdit" to get window id 3210
|
47
|
+
# p textedit.windows.ID(3210).get
|
48
48
|
|
49
49
|
|
50
|
-
# tell application "TextEdit" to get a reference to text of document 1
|
51
|
-
p textedit.documents[1].text
|
50
|
+
# tell application "TextEdit" to get a reference to text of document 1
|
51
|
+
p textedit.documents[1].text
|
52
52
|
|
53
53
|
|
54
|
-
# tell application "TextEdit" to get text of document 1
|
55
|
-
p textedit.documents[1].text.get
|
54
|
+
# tell application "TextEdit" to get text of document 1
|
55
|
+
p textedit.documents[1].text.get
|
56
56
|
|
57
57
|
|
58
|
-
# tell application "TextEdit" to make new document at end of documents
|
59
|
-
textedit.documents.end.make(:new => :document)
|
58
|
+
# tell application "TextEdit" to make new document at end of documents
|
59
|
+
textedit.documents.end.make(:new => :document)
|
60
60
|
|
61
61
|
|
62
|
-
# tell application "TextEdit" to set text of document 1 to "Happy Happy Joy Joy\n"
|
63
|
-
textedit.documents[1].text.set("Happy Happy Joy Joy\n")
|
62
|
+
# tell application "TextEdit" to set text of document 1 to "Happy Happy Joy Joy\n"
|
63
|
+
textedit.documents[1].text.set("Happy Happy Joy Joy\n")
|
64
64
|
|
65
65
|
|
66
|
-
# tell application "TextEdit" to get text of every document
|
67
|
-
p textedit.documents.text.get
|
66
|
+
# tell application "TextEdit" to get text of every document
|
67
|
+
p textedit.documents.text.get
|
68
68
|
|
69
69
|
|
70
|
-
# tell application "TextEdit" to count each word of text of document 1
|
71
|
-
p textedit.documents[1].text.count(:each => :word)
|
70
|
+
# tell application "TextEdit" to count each word of text of document 1
|
71
|
+
p textedit.documents[1].text.count(:each => :word)
|
72
72
|
|
73
73
|
|
74
|
-
# tell application "TextEdit" to get words 3 thru -1 of document 1
|
75
|
-
p textedit.documents[1].words[3, -1].get
|
74
|
+
# tell application "TextEdit" to get words 3 thru -1 of document 1
|
75
|
+
p textedit.documents[1].words[3, -1].get
|
76
76
|
|
77
77
|
|
78
|
-
# tell application "TextEdit" to set size of character 1 of every word
|
79
|
-
# of document 1 to 24
|
80
|
-
textedit.documents[1].words.characters[1].size.set(24)
|
78
|
+
# tell application "TextEdit" to set size of character 1 of every word
|
79
|
+
# of document 1 to 24
|
80
|
+
textedit.documents[1].words.characters[1].size.set(24)
|
81
81
|
|
82
82
|
|
83
|
-
# tell application "TextEdit" to set color of any word of document 1 to {65535, 0, 0}
|
84
|
-
textedit.documents[1].words.any.color.set([65535, 0, 0])
|
83
|
+
# tell application "TextEdit" to set color of any word of document 1 to {65535, 0, 0}
|
84
|
+
textedit.documents[1].words.any.color.set([65535, 0, 0])
|
85
85
|
|
86
86
|
|
87
|
-
# tell application "TextEdit" to make new paragraph at
|
88
|
-
# (after last paragraph of text of document 1) with data "Silly Rabbit\n"
|
89
|
-
textedit.documents[1].text.paragraphs.last.after.make(
|
90
|
-
|
87
|
+
# tell application "TextEdit" to make new paragraph at
|
88
|
+
# (after last paragraph of text of document 1) with data "Silly Rabbit\n"
|
89
|
+
textedit.documents[1].text.paragraphs.last.after.make(
|
90
|
+
:new => :paragraph, :with_data => "Silly Rabbit\n")
|
91
91
|
|
92
92
|
|
93
|
-
# tell application "TextEdit" to get paragraph after paragraph 1 of document 1
|
94
|
-
p textedit.documents[1].paragraphs[1].next(:paragraph).get
|
93
|
+
# tell application "TextEdit" to get paragraph after paragraph 1 of document 1
|
94
|
+
p textedit.documents[1].paragraphs[1].next(:paragraph).get
|
95
95
|
|
96
96
|
|
97
|
-
# tell application "TextEdit" to make new document at end of documents
|
98
|
-
# with properties {text:"foo\nbar\n\n\nbaz\n\nfub\n"}
|
99
|
-
textedit.documents.end.make(:new => :document,
|
100
|
-
|
97
|
+
# tell application "TextEdit" to make new document at end of documents
|
98
|
+
# with properties {text:"foo\nbar\n\n\nbaz\n\nfub\n"}
|
99
|
+
textedit.documents.end.make(:new => :document,
|
100
|
+
:with_properties => {:text => "foo\nbar\n\n\nbaz\n\nfub\n"})
|
101
101
|
|
102
102
|
|
103
|
-
# tell application "TextEdit" to get every paragraph of text of document 1
|
104
|
-
p textedit.documents[1].text.paragraphs.get
|
103
|
+
# tell application "TextEdit" to get every paragraph of text of document 1
|
104
|
+
p textedit.documents[1].text.paragraphs.get
|
105
105
|
|
106
106
|
|
107
|
-
# tell application "TextEdit" to get every paragraph of document 1
|
108
|
-
# where it is not "\n" -- get non-empty paragraphs
|
109
|
-
p textedit.documents[1].paragraphs[its.ne("\n")].get
|
107
|
+
# tell application "TextEdit" to get every paragraph of document 1
|
108
|
+
# where it is not "\n" -- get non-empty paragraphs
|
109
|
+
p textedit.documents[1].paragraphs[its.ne("\n")].get
|
110
110
|
|
111
111
|
|
112
|
-
# tell application "TextEdit" to get text of every document
|
113
|
-
# whose text begins with "H"
|
114
|
-
p textedit.documents[its.text.begins_with('H')].text.get
|
112
|
+
# tell application "TextEdit" to get text of every document
|
113
|
+
# whose text begins with "H"
|
114
|
+
p textedit.documents[its.text.begins_with('H')].text.get
|
115
115
|
|
116
116
|
|
117
117
|
|
118
|
-
# The following examples don't work in TextEdit but will work in,
|
119
|
-
# for example, Tex-Edit Plus:
|
120
|
-
#
|
121
|
-
# # tell application "Tex-Edit Plus" to get words (character 5)
|
122
|
-
# # thru (paragraph 9) of document 1
|
123
|
-
# p app('Tex-Edit Plus').documents[1] \
|
124
|
-
# .words[con.characters[5], con.paragraphs[9]].get
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# # tell application "Tex-Edit Plus" to get every word of text
|
128
|
-
# # of document 1 whose color is {0, 0, 0}
|
129
|
-
# p app('Tex-Edit Plus').documents[1].text.paragraphs \
|
130
|
-
# [its.color.equals((0, 0, 0))].get
|
118
|
+
# The following examples don't work in TextEdit but will work in,
|
119
|
+
# for example, Tex-Edit Plus:
|
120
|
+
#
|
121
|
+
# # tell application "Tex-Edit Plus" to get words (character 5)
|
122
|
+
# # thru (paragraph 9) of document 1
|
123
|
+
# p app('Tex-Edit Plus').documents[1] \
|
124
|
+
# .words[con.characters[5], con.paragraphs[9]].get
|
125
|
+
#
|
126
|
+
#
|
127
|
+
# # tell application "Tex-Edit Plus" to get every word of text
|
128
|
+
# # of document 1 whose color is {0, 0, 0}
|
129
|
+
# p app('Tex-Edit Plus').documents[1].text.paragraphs \
|
130
|
+
# [its.color.equals((0, 0, 0))].get
|
@@ -8,14 +8,14 @@
|
|
8
8
|
# Note: if using the appscript gem, rubygems must be required first:
|
9
9
|
begin; require 'rubygems'; rescue LoadError; end
|
10
10
|
|
11
|
-
require 'appscript'
|
12
|
-
include Appscript
|
13
|
-
require 'osax'
|
14
|
-
require "amrita/template"
|
15
|
-
include Amrita
|
11
|
+
require 'appscript'
|
12
|
+
include Appscript
|
13
|
+
require 'osax'
|
14
|
+
require "amrita/template"
|
15
|
+
include Amrita
|
16
16
|
|
17
|
-
# Amrita HTML template
|
18
|
-
tmpl = TemplateText.new <<END
|
17
|
+
# Amrita HTML template
|
18
|
+
tmpl = TemplateText.new <<END
|
19
19
|
<html>
|
20
20
|
<head>
|
21
21
|
<title> iTunes Top 40 Tracks</title>
|
@@ -41,31 +41,29 @@ tmpl = TemplateText.new <<END
|
|
41
41
|
</html>
|
42
42
|
END
|
43
43
|
|
44
|
-
# Choose the file to write
|
45
|
-
sa = OSAX.osax('StandardAdditions')
|
46
|
-
out_file = sa.choose_file_name(:default_name=>'My-iTunes-Top-40.html')
|
44
|
+
# Choose the file to write
|
45
|
+
sa = OSAX.osax('StandardAdditions')
|
46
|
+
out_file = sa.choose_file_name(:default_name=>'My-iTunes-Top-40.html')
|
47
47
|
|
48
|
-
# Get the played count, name and album for every track in iTunes
|
49
|
-
tracks = app('iTunes').library_playlists[1].tracks
|
50
|
-
info = tracks.played_count.get.zip(tracks.name.get, tracks.album.get)
|
51
|
-
# Extract the top 40 most played entries
|
52
|
-
top40 = info.sort.reverse[0, 40]
|
48
|
+
# Get the played count, name and album for every track in iTunes
|
49
|
+
tracks = app('iTunes').library_playlists[1].tracks
|
50
|
+
info = tracks.played_count.get.zip(tracks.name.get, tracks.album.get)
|
51
|
+
# Extract the top 40 most played entries
|
52
|
+
top40 = info.sort.reverse[0, 40]
|
53
53
|
|
54
|
-
# Assemble input data for Amrita
|
55
|
-
data = {
|
56
|
-
|
57
|
-
}
|
54
|
+
# Assemble input data for Amrita
|
55
|
+
data = {
|
56
|
+
:table_row=>top40.collect { |row_data| {:table_column=>row_data} }
|
57
|
+
}
|
58
58
|
|
59
|
-
# Render HTML file
|
60
|
-
tmpl.prettyprint = true
|
61
|
-
File.open(out_file.to_s, 'w') { |f| tmpl.expand(f, data) }
|
62
|
-
|
63
|
-
# Open file in Safari for viewing
|
64
|
-
# safari = app('Safari')
|
65
|
-
# safari.activate
|
66
|
-
# safari.open(out_file)
|
67
|
-
|
68
|
-
# Open file in default web browser for viewing
|
69
|
-
sa.open_location(out_file.url)
|
59
|
+
# Render HTML file
|
60
|
+
tmpl.prettyprint = true
|
61
|
+
File.open(out_file.to_s, 'w') { |f| tmpl.expand(f, data) }
|
70
62
|
|
63
|
+
# Open file in Safari for viewing
|
64
|
+
# safari = app('Safari')
|
65
|
+
# safari.activate
|
66
|
+
# safari.open(out_file)
|
71
67
|
|
68
|
+
# Open file in default web browser for viewing
|
69
|
+
sa.open_location(out_file.url)
|