Skip to content

Instantly share code, notes, and snippets.

@matiaskorhonen
Created June 14, 2013 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiaskorhonen/5783255 to your computer and use it in GitHub Desktop.
Save matiaskorhonen/5783255 to your computer and use it in GitHub Desktop.
Alfred myPhoneDesktop process (from `ps aux`)
matt 3225 0.1 0.0 2434120 1920 ?? Ss 7:18PM 0:00.01 /usr/bin/ruby -e #!/usr/bin/env ruby^J# encoding: utf-8^J^J# myPhoneDesktop for Alfred extension^J# v2.0, 03/14/2013^J# Author: jProductivity^J# Copyright © 2013 jProductivity, LLC^J# http://www.myphonedesktop.com/^J^J# visit http://support.myphonedesktop.com/entries/20929458-myphonedesktop-for-alfred-app-extension-send-to-iphone ^J# for instructions on how to install and use this extension^J^J# To control how phone number and SMS text will be processed set property AUTO_SEND to "true" or "false"^J^J# "true" - will send selected phone number and SMS text to iPhone and will automatically launch iPhone's Messages.app;^J# NOTE: iPhone's Messages.app will auto open only if myPhoneDesktop's iPhone app | Settings | View Options | Auto Respond | SMS option is set to ON^J^J# "false" - will only copy this phone number and SMS text to myPhoneDesktop's desktop client and will not send it to iPhone^J^J# NOTE: in order for AUTO_SEND property to have an effect the USE_DESKTOP_AUTO_SEND_RULES property must be set to "false"^J^J# If AUTO_SEND property is set to either "true" or "false"^J# it will override all "Auto Send" options set in "Phone Options" of myPhoneDesktop's desktop client.^J# You can control this by setting USE_DESKTOP_AUTO_SEND_RULES property to "true" or "false".^J# If USE_DESKTOP_AUTO_SEND_RULES property is set to "true" then script will honor all "Auto Send" options set in^J# "Phone Options" of myPhoneDesktop's desktop client^J^J^JAPP_NAME = "mpd"^JAPP_PATH = "/Applications/myPhoneDesktop.app"^JUSE_DESKTOP_AUTO_SEND_RULES = true^JAUTO_SEND = true^J^Jdef mpd_installed?^J File.exist?("#{APP_PATH}") ? true : false^Jend^J^Jdef mpd_running?(app_name)^J `pgrep -f myPhoneDesktop.app`.length > 0^Jend^J^Jdef can_send_to_mpd?^J unless mpd_installed?^J `osascript -e 'tell application "System Events"' -e 'display dialog "There is no myPhoneDesktop installed on your computer. Visit the myPhoneDesktop site to download and install myPhoneDesktop on your computer, iPhone, iPad or iPod touch." with title "myPhoneDesktop is not installed" with icon 2 buttons {"OK"} default button 1' -e 'open location "http://www.myphonedesktop.com/"' -e 'end tell'`^J puts "myPhoneDesktop extension for Alfred :: myPhoneDesktop is not installed! Download from http://www.myphonedesktop.com/"^J Process.exit^J end^J^J unless mpd_running?("myPhoneDesktop.app")^J `open -a \"#{APP_PATH}\"`^J sleep(5)^J end^J mpd_running?("myPhoneDesktop.app")^Jend^J^Jdef is_phone?^J #get data before the pipe^J result = "foo".split(/\|/i)^J^J #Strip all chars except alphanumeric and +^J clean_phone_number = result[0].gsub(/[^0-9a-z\+]/i, '')^J^J #Check if first parameter is the phone number matching NANP Format^J # NANP Format: http://www.nanpa.com/about_us/abt_nanp.html^J nanp_format = clean_phone_number =~ /\A(?:(?x)^((\*?|\#?)[0-9]+\#{1})?(?:\+?1[-.\x20]?)?\(?([2-9][0-8][0-9])\)?[-.\x20]?([2-9][0-9]{2})[-.\x20]?([0-9]{4})$)\Z/i ? true : false^J^J # Check if first parameter is the phone number matching N11 Format^J # http://en.wikipedia.org/wiki/N11_code^J n11_format = clean_phone_number =~ /\A(?:(?x)^(?:\+?(?:211|311|411|511|611|711|811|911))$)\Z/i ? true : false^J^J # Check if first parameter is the phone number matching Generic International Format^J international_format = clean_phone_number =~ /\A((?x)^((\*?|\#?)[0-9]+\#{1})?\+(?:[0-9]\x20?){6,14}[0-9]$)\Z/i ? true : false^J^J # Check if first parameter is the phone number matching format of Vanity numbers in the United States^J #http://en.wikipedia.org/wiki/Phoneword#Vanity_numbers_in_the_United_States^J vanity_format = clean_phone_number =~ /\A(?:(?x)^((\*?|\#?)[0-9]+\#{1})?(?:\+?1[-.]?)?\(?(800|888|877|866|855|844|833|822|880|887|889)\)?([-.0-9a-z]{7,})$)\Z/i ? true : false^J^J nanp_format || n11_format || international_format || vanity_format ? true : false^Jend^J^Jdef is_sms?^J "foo" =~ /\|/i ? true : false^Jend^J^Jdef process_query(data)^J is_file = File.exist?(data) && ! File.directory?(data)^J^J if is_file^J t = Thread.new do^J `osascript -e 'set the clipboard to POSIX file "#{data}"'`^J end^J t.join^J else^J if is_phone? && is_sms? then^J if USE_DESKTOP_AUTO_SEND_RULES then^J data = "${command=phoneSMS}|#{data}"^J else^J data = "${command=phoneSMS; autoSend=#{AUTO_SEND}}|#{data}"^J end^J end^J^J data = data.gsub(/["]/i, '\\"')^J t = Thread.new do^J `osascript -e 'set the clipboard to "#{data}" as Unicode text'`^J end^J t.join^J end^J^J send_to_mpd^Jend^J^Jdef send_to_mpd^J `osascript -e 'tell application "System Events"' -e 'key code 113 using {shift down, control down, option down, command down}' -e 'end tell'`^Jend^J^Junless "foo".nil? || "foo" == 0^J if can_send_to_mpd?^J ^I#`syslog -s -l notice "foo"`^J process_query("foo".strip)^J else^J puts "myPhoneDesktop workflow for Alfred :: myPhoneDesktop is not running. Unable to send data to myPhoneDesktop"^J end^Jend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment