imsg 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +45 -10
- data/bin/imsg +29 -0
- data/lib/imsg.rb +44 -41
- data/lib/imsg/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81a94e2ace83d8ccc93b41b0f081aaebc8eab97
|
4
|
+
data.tar.gz: 6b243ee65b0bd53c88b7bc1c59116059b939dc42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68fe23cc2f81337e01243412ed5aaabf5bb48156d4575fc94c346e9a50316f9a1cfdd62a1e3ee5d9e201e8660a03c262877bf54fb0caaa3c306b26c1dfd36207
|
7
|
+
data.tar.gz: 4aaf1e3c6fb502cebd810aea86bb4393eb2df6b9a6a54450dee5cce33e39248b43571743533370cf2f4a3e73d07e359dd038eafcf074f7094237c0c85922041f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,56 @@
|
|
1
1
|
# imsg
|
2
2
|
|
3
|
-
Tired of getting off your terminal screen to answer
|
4
|
-
Now you can curse them right
|
3
|
+
Tired of getting off your terminal screen to answer those dickhead friends of yours?
|
4
|
+
Now you can curse them right from the terminal!
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
|
8
|
+
It is easy as:
|
9
9
|
|
10
|
-
|
10
|
+
```bash
|
11
|
+
$ gem install imsg
|
12
|
+
```
|
11
13
|
|
12
|
-
|
14
|
+
## Usage
|
13
15
|
|
14
|
-
|
16
|
+
```bash
|
17
|
+
$ imsg HELLOOO FROM TERMINAL
|
18
|
+
```
|
15
19
|
|
16
|
-
|
20
|
+
Then select a number corresponding to the person you wish to message
|
17
21
|
|
18
|
-
|
22
|
+
To which chat you wanna send your message?
|
23
|
+
(You can choose a number or type a buddy name/email)
|
24
|
+
1 - Christian Sampaio
|
25
|
+
2 - Linus Torvalds
|
26
|
+
3 - Tim Berners Lee
|
27
|
+
4 - Steve Wozniak
|
28
|
+
5 - Sergey Brin
|
29
|
+
6 - Larry Page
|
30
|
+
```bash
|
31
|
+
$ 4
|
32
|
+
```
|
19
33
|
|
20
|
-
##
|
34
|
+
## Common problems
|
35
|
+
###Using special characters
|
36
|
+
If you wanna use special characters like parentheses, brackets or quotes you need to escape it. i.e.:
|
37
|
+
```bash
|
38
|
+
$ imsg HELLOOO FROM TERMINAL \(ESCAPIIING\)
|
39
|
+
```
|
40
|
+
or
|
41
|
+
```bash
|
42
|
+
$ imsg "HELLOOO FROM TERMINAL (ESCAPIIING)"
|
43
|
+
```
|
44
|
+
|
45
|
+
###Not having write permissions:
|
21
46
|
|
22
|
-
|
47
|
+
If you don't have write access to your Ruby folder:
|
23
48
|
|
49
|
+
```bash
|
50
|
+
$ sudo gem install imsg
|
51
|
+
```
|
52
|
+
|
53
|
+
|
24
54
|
## Contributing
|
25
55
|
|
26
56
|
1. Fork it ( http://github.com/chrisfsampaio/imsg/fork )
|
@@ -29,4 +59,9 @@ imsg HELLLO FROM TERMINAL
|
|
29
59
|
4. Push to the branch (`git push origin my-new-feature`)
|
30
60
|
5. Create new Pull Request
|
31
61
|
|
62
|
+
## Contact
|
63
|
+
christian.fsampaio@gmail.com
|
64
|
+
http://chrisfsampaio.github.io
|
65
|
+
|
66
|
+
|
32
67
|
#<3
|
data/bin/imsg
CHANGED
@@ -1,2 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'imsg'
|
3
|
+
|
4
|
+
def interactWithUser
|
5
|
+
# Gets the message and concatenate it into a string
|
6
|
+
str = ""
|
7
|
+
ARGV.each do |value|
|
8
|
+
str +=value+" "
|
9
|
+
end
|
10
|
+
str = str.chomp(' ');
|
11
|
+
ARGV.clear
|
12
|
+
STDOUT.flush
|
13
|
+
|
14
|
+
# Show the chat list with the buddies names
|
15
|
+
ImsgHandler.showChatList
|
16
|
+
|
17
|
+
# Gets the buddy name or number
|
18
|
+
response = gets.chomp
|
19
|
+
|
20
|
+
# Send the message captured on the beggining to the selected buddy
|
21
|
+
ImsgHandler.sendMessage str, response
|
22
|
+
end
|
23
|
+
|
24
|
+
# Control+C trick in order to get out of command gracefully
|
25
|
+
trap("SIGINT") { throw :ctrl_c }
|
26
|
+
catch :ctrl_c do
|
27
|
+
begin
|
28
|
+
interactWithUser
|
29
|
+
rescue Exception
|
30
|
+
end
|
31
|
+
end
|
data/lib/imsg.rb
CHANGED
@@ -2,49 +2,52 @@
|
|
2
2
|
require "imsg/version"
|
3
3
|
require 'appscript'
|
4
4
|
|
5
|
-
|
6
|
-
retVal = ""
|
7
|
-
count = 1
|
8
|
-
buddies.each do |buddy|
|
9
|
-
retVal += count.to_s + " - " +buddy.join(',') +"\n"
|
10
|
-
count += 1
|
11
|
-
end
|
12
|
-
retVal
|
13
|
-
end
|
5
|
+
module ImsgHandler
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
# Formats a list of buddies objects retrieved by Applescript into a readable list
|
8
|
+
# returns a formatted String
|
9
|
+
def self.formatBuddies buddies
|
10
|
+
formatedString = ""
|
11
|
+
count = 1
|
12
|
+
buddies.each do |buddy|
|
13
|
+
formatedString += " " + count.to_s + " - " + buddy.join(',') + "\n"
|
14
|
+
count += 1
|
15
|
+
end
|
16
|
+
formatedString
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
str = str.chomp(' ');
|
24
|
-
ARGV.clear
|
25
|
-
STDOUT.flush
|
19
|
+
# Check if a String is a integer number
|
20
|
+
def self.is_i str
|
21
|
+
!!(str =~ /^[-+]?[0-9]+$/)
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
a
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
puts "(You can choose a number or type a buddy name/email)\n\n"
|
39
|
-
puts formatBuddies b
|
24
|
+
# Calls Applescript in order to trigger an iMessage message to a buddy
|
25
|
+
# The buddy parameter accepts a String with either a chat number or a Buddy name
|
26
|
+
def self.sendMessage message, buddy
|
27
|
+
if is_i buddy
|
28
|
+
puts "Sending \'#{message}\' to chat number #{buddy}"
|
29
|
+
`osascript -e 'tell application "Messages" to send \"#{message}\" to item #{buddy.to_i} of text chats'`
|
30
|
+
else
|
31
|
+
puts "Sending \'#{message}\' to buddy \'#{buddy}\'"
|
32
|
+
`osascript -e 'tell application "Messages" to send \"#{message}\" to buddy \"#{buddy}\"'`
|
33
|
+
end
|
34
|
+
end
|
40
35
|
|
36
|
+
# Shows the chat list along with their participants
|
37
|
+
def self.showChatList
|
38
|
+
imsg = Appscript.app("Messages")
|
39
|
+
participants = imsg.chats.participants.get()
|
40
|
+
participantsByChat = []
|
41
|
+
participants.each do |v|
|
42
|
+
names = []
|
43
|
+
v.each do |buddy|
|
44
|
+
names.push buddy.name.get()
|
45
|
+
end
|
46
|
+
participantsByChat.push names
|
47
|
+
end
|
48
|
+
puts "\nWho would you like to send your message to?"
|
49
|
+
puts "(You can choose a number or type a buddy name/email)\n\n"
|
50
|
+
puts formatBuddies participantsByChat
|
51
|
+
end
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
if is_i response
|
45
|
-
puts "Sending \'#{str}\' to chat number #{response}"
|
46
|
-
`osascript -e 'tell application "Messages" to send \"#{str}\" to item #{response.to_i} of text chats'`
|
47
|
-
else
|
48
|
-
puts "Sending \'#{str}\' to buddy \'#{response}\'"
|
49
|
-
`osascript -e 'tell application "Messages" to send \"#{str}\" to buddy \"#{response}\"'`
|
50
|
-
end
|
53
|
+
end
|
data/lib/imsg/version.rb
CHANGED