tunees 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18903b118ba754dc05a8739f741d0514ecb07427
4
- data.tar.gz: 1e520613f20bcee4c465faa3a8099b7f0887833c
3
+ metadata.gz: ff5b5067a291104d41fe24c62570a5a02fd6ff2c
4
+ data.tar.gz: a890feace1671cf7431d69516bf1b4b3e10eb3b0
5
5
  SHA512:
6
- metadata.gz: 8e9317894c7d0620def7219f4a7f837bec27924b2ad1c1de27ffd4e17c40b9bb4b324b0c9bf35bb68baf76754f38c9942dec9871e5435c7ae444cfc1bedbd509
7
- data.tar.gz: df46ca66af91f5114a9190ed0b447318ae1d87d803a521baa45b1019e5920139f81d8be8f998b6d5209ed14ead28671807a36e95610bb995ad5632783c232d98
6
+ metadata.gz: b9cdd6552a365e5f2111d66cf8362ba405f33f82cf8c037140f20e6dbd9069c8aee331e9ead15d4c7f793df8d0d2110db355de665278f03cb4576f1e46abe9fc
7
+ data.tar.gz: 4dd8c22b67de39b32368d58ba6d6a9ccdeb1f6bbba9e7281ec7288dbf23aca6a2f5129c81a43b11f0a416964a1c1f029b08131121faabee5a427239eec7dc657
@@ -8,7 +8,14 @@ module Tunees
8
8
  def self.execute(method, *args)
9
9
  Commander.run <<-JXA.strip_heredoc
10
10
  var app = Application("iTunes")
11
- app.#{method}()
11
+ return app.#{method}(#{args.join(",")})
12
+ JXA
13
+ end
14
+
15
+ def self.set_property(property, value)
16
+ Commander.run <<-JXA.strip_heredoc
17
+ var app = Application("iTunes")
18
+ app.#{property} = #{value}
12
19
  JXA
13
20
  end
14
21
 
@@ -40,5 +47,80 @@ module Tunees
40
47
  execute(camel_cased_method, *args)
41
48
  end
42
49
  end
50
+
51
+ # Application elements
52
+ %w(
53
+ airplayDevices
54
+ browserWindows
55
+ encoders
56
+ eqPresets
57
+ eqWindows
58
+ playlistWindows
59
+ sources
60
+ audioCDPlaylists
61
+ audioCDTracks
62
+ libraryPlaylists
63
+ fileTracks
64
+ urlTracks
65
+ sharedTracks
66
+ playlists
67
+ tracks
68
+ artworks
69
+ radioTunerPlaylists
70
+ urlTracks
71
+ userPlaylists
72
+ fileTracks
73
+ urlTracks
74
+ sharedTracks
75
+ visuals
76
+ windows
77
+ ).uniq.each do |camel_cased_element|
78
+ method = camel_cased_element.underscore
79
+ define_singleton_method(method) do
80
+ execute(camel_cased_element)
81
+ end
82
+ end
83
+
84
+ # Application properties
85
+ [
86
+ [:airplayEnabled, false],
87
+ [:converting, false],
88
+ [:currentAirPlayDevices, true],
89
+ [:currentEncoder, true],
90
+ [:currentEQPreset, true],
91
+ [:currentPlaylist, false],
92
+ [:currentStreamTitle, false],
93
+ [:currentStreamURL, false],
94
+ [:currentTrack, false],
95
+ [:currentVisual, true],
96
+ [:eqEnabled, true],
97
+ [:fixedIndexing, true],
98
+ [:frontmost, true],
99
+ [:fullScreen, true],
100
+ [:name, false],
101
+ [:mute, true],
102
+ [:playerPosition, true],
103
+ [:playerState, false],
104
+ [:selection, false],
105
+ [:soundVolume, true],
106
+ [:version, false],
107
+ [:visualsEnabled, true],
108
+ [:visualSize, true],
109
+ [:iadIdentifier, false],
110
+ ].each do |camel_cased_property, writable|
111
+ method = camel_cased_property.to_s.underscore
112
+
113
+ # reader
114
+ define_singleton_method(method) do
115
+ execute(camel_cased_property.to_s)
116
+ end
117
+
118
+ # writer
119
+ if writable
120
+ define_singleton_method("#{method}=") do |value|
121
+ set_property(camel_cased_property.to_s, value)
122
+ end
123
+ end
124
+ end
43
125
  end
44
126
  end
@@ -1,11 +1,10 @@
1
+ require 'execjs/runtimes/jxa'
2
+ ExecJS.runtime = ExecJS::Runtimes::JXA
3
+
1
4
  module Tunees
2
5
  class Commander
3
6
  def self.run(script)
4
- IO.popen("osascript -l JavaScript", "r+") do |io|
5
- io.puts script
6
- io.close_write
7
- io.gets
8
- end
7
+ ExecJS.exec(script)
9
8
  end
10
9
  end
11
10
  end
@@ -1,3 +1,3 @@
1
1
  module Tunees
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "activesupport"
22
+ spec.add_dependency "execjs-runtimes-jxa"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.10"
24
25
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tunees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - meganemura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: execjs-runtimes-jxa
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement