Permalink
Browse files

Use Apple choose color.

  • Loading branch information...
1 parent d0cf6fb commit 2696df2aba5a0d2841ba395f6c5fb0530c311098 @nobios nobios committed with infininight Sep 19, 2012
Showing with 17 additions and 12 deletions.
  1. +17 −12 Commands/Insert Color.plist
@@ -176,23 +176,28 @@ def request_color(string = nil)
string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}'
begin
- col = `osascript -e 'tell app "FastScripts" to choose color#{def_col}'`
+ col = `osascript << EOT
+tell app "AppleScript Runner"
+ activate
+ set RGB_values to choose color #{def_col}
+ set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
+ set the the hex_value to ""
+ repeat with i from 1 to the count of the RGB_values
+ set this_value to (item i of the RGB_values) div 256
+ if this_value is 256 then set this_value to 255
+ set x to item ((this_value div 16) + 1) of the hex_list
+ set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list
+ set the hex_value to (the hex_value & x & y) as string
+ end repeat
+ return ("#" & the hex_value) as string
+end
+EOT`
rescue
return col = string
end
reactivate
exit 200 if col.empty? # user cancelled -- when it happens, an exception is written to stderr
- col = col.scan(/\d+/).map { |i| "%02X" % (i.to_i / 257) }.join("")
- # Add : # ; back if they were in the input
- m = original_color.match(/(:? ?).*?( ?;?)$/)
- color = m[1] + prefix
- suffix = m[2].empty? ? "" : "$0" + m[2]
-
- if /(.)\1(.)\2(.)\3/.match(col)
- color << $1 + $2 + $3 + suffix
- else
- color << col + suffix
- end
+ color = col.strip
end
print request_color(input).downcase

0 comments on commit 2696df2

Please sign in to comment.