├── README.markdown ├── gcdialer.applescript └── class.grandcentral.php /README.markdown: -------------------------------------------------------------------------------- 1 | Basic Usage 2 | ----------- 3 | 4 | Dialing a number is simple 5 | 6 | $gc = new GrandCentral('', ''); 7 | $gc->call($your_phone_number, $their_phone_number); 8 | 9 | You can also use the included AppleScript file to dial a number directly from Address Book. 10 | 11 | License 12 | ------- 13 | 14 | This code is released under the MIT Open Source License. Feel free to do whatever you want with it. 15 | -------------------------------------------------------------------------------- /gcdialer.applescript: -------------------------------------------------------------------------------- 1 | -- This script lets you dial a phone number in Address Book using -- one of your Grand Central phone numbers. (i.e. the ones GC rings -- when you have an incoming call.) -- Most of this code was adapted from the scripts that come with BluePhoneElite. -- http://mirasoftware.com/BPE2/ using terms from application "Address Book" on action property return "phone" end action property on action title for thePerson with theEntry return "Dial with GrandCentral" end action title on should enable action for thePerson with theEntry return (theEntry is not missing value) end should enable action on perform action for thePerson with theEntry return gcdial(value of theEntry as string) end perform action end using terms from on gcdial(thePhoneNumber) set pathToDialer to "~/Library/Scripts/gcdialer.php" set yourPhoneNumber to "5551234567" do shell script pathToDialer & " " & yourPhoneNumber & " " & quoted form of thePhoneNumber end gcdial -------------------------------------------------------------------------------- /class.grandcentral.php: -------------------------------------------------------------------------------- 1 | login($username, $password); 10 | } 11 | 12 | // Login to GrandCentral. 13 | public function login($username, $password) 14 | { 15 | $this->curl('http://www.grandcentral.com'); 16 | $headers = $this->curl('http://www.grandcentral.com/account/login_from_flash/', 'http://www.grandcentral.com', "remember_me=0&login_password=$password&login_id=$username", true); 17 | $this->a_t = $this->match('/a_t=([^;]+)/', $headers, 1); 18 | } 19 | 20 | // Connect $you to $them. Takes two 10 digit US phone numbers. 21 | public function call($you, $them) 22 | { 23 | $you = preg_replace('/[^0-9]/', '', $you); 24 | $them = preg_replace('/[^0-9]/', '', $them); 25 | $this->curl("http://grandcentral.com/calls/send_call_request?a_t={$this->a_t}&category_id=undefined&contact_id=undefined&calltype=call&destno=$them&ani=$you"); 26 | } 27 | 28 | // From: http://code.google.com/p/simple-php-framework/ 29 | private function curl($url, $referer = null, $post = null, $return_header = false) 30 | { 31 | static $tmpfile; 32 | 33 | if(!isset($tmpfile) || ($tmpfile == '')) $tmpfile = tempnam('/tmp', 'FOO'); 34 | 35 | $ch = curl_init($url); 36 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 37 | curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfile); 38 | curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile); 39 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 40 | curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061024 BonEcho/2.0"); 41 | if($referer) curl_setopt($ch, CURLOPT_REFERER, $referer); 42 | 43 | if(!is_null($post)) 44 | { 45 | curl_setopt($ch, CURLOPT_POST, true); 46 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 47 | } 48 | 49 | if($return_header) 50 | { 51 | curl_setopt($ch, CURLOPT_HEADER, 1); 52 | $html = curl_exec($ch); 53 | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 54 | return substr($html, 0, $header_size); 55 | } 56 | else 57 | { 58 | $html = curl_exec($ch); 59 | return $html; 60 | } 61 | } 62 | 63 | // From: http://code.google.com/p/simple-php-framework/ 64 | private function match($regex, $str, $i = 0) 65 | { 66 | return preg_match($regex, $str, $match) == 1 ? $match[$i] : false; 67 | } 68 | } 69 | --------------------------------------------------------------------------------