The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   Check Landline Dialler testing (http://hintsforums.macworld.com/showthread.php?t=49338)

mark hunte 12-30-2005 09:18 AM

Check Landline Dialler testing
 
Hi all I wonder if any of you can run this script for me. before I submit it.
Its a simple plugin to dial from address book using you internal modem and landline.

It works great here, but I want to know if the speaker for modems is always set to ON as default, if not how to set it to ON when using the script.

To use it save it into

/Library/Address Book Plug-Ins/

plug your landline in (using a Modem cable, a normal cable may not work)

open AB select a phone number label and select

Dial using LandLine

Please let me know if there are any other issues.

I want to do this through Address Book. as a plugin so please do not let me know if there are apps out there already.

Please do let me know if there is a way to access the internal modem to dial without going through Internet connect. or visible app, maybe using do shell and some CLI (in fact the more I think about it there should be a CLI way)

Thanks in advance....

the code.

Code:

using terms from application "Address Book"
        on action property
                return "phone"
        end action property
       
        on action title for p with e
                return "Dial using LandLine"
        end action title
       
        on should enable action for p with e
                return true
        end should enable action
       
        on perform action for p with e
                set phone_num to the value of e
               
                -- Clean up the number from any extraneous characters
                -- like blanks, '(', ')', '-' .
                set phone_num to replace_chars(phone_num, "-", "")
                set phone_num to replace_chars(phone_num, "(", "")
                set phone_num to replace_chars(phone_num, ")", "")
                set phone_num to replace_chars(phone_num, " ", "")
               
                -- See if number already starts with '+'
                if phone_num starts with "+" then
                        -- If not, prepend "0" to the number and remove the +44
                        set phone_num to "0" & characters 4 thru -1 of phone_num
                       
                end if
                land_out(phone_num)
        end perform action
       
end using terms from

on land_out(phone_num)
        tell application "Internet Connect"
               
                connect configuration "Internal Modem" to telephone number phone_num
                tell application "System Events" to set visible of application process "Internet Connect" to false
                tell application "Finder"
                        display dialog "When you Hear Dialing choose" buttons {"Disconnect", "Pick-Up"} default button 2
                        if the button returned of the result is "Disconect" then
                                tell application "Internet Connect"
                                        disconnect
                                end tell
                        else
                                tell application "Internet Connect"
                                        delay 2 -- appx time it takes to pick up phone after hitting pick up button
                                        disconnect
                                end tell
                        end if
                       
                end tell
                get properties of current configuration
        end tell
end land_out

-- Text replace function
on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars


hayne 12-30-2005 12:53 PM

Quote:

Originally Posted by mark hunte
Please do let me know if there is a way to access the internal modem to dial without going through Internet connect. or visible app, maybe using do shell and some CLI (in fact the more I think about it there should be a CLI way)

From the results of 'man -k modem' I see that I have two CLI programs that might work for your purpose:
/usr/sbin/chat
/usr/bin/efax
Reading their man pages shows that both of them can do dialing.
The 'chat' program evidently comes via Fink.

Another possibility might be to use the programmatic access to the serial port as illustrated in this Apple example:
http://developer.apple.com/samplecod...ortSample.html
and as bundled up in this Cocoa class:
http://www.harmless.de/cocoa.html#serialport

mark hunte 01-01-2006 08:32 AM

Thanks hayne,

i have got the efax dialling, took me a bit to get it to dial in tone instead of pulse.

Still working with it, and may skip to the other options.


p.s

Happy New year to you and yours.

mark hunte 01-08-2006 05:48 PM

Hi Hayne, thanks for your help

Working out eFax was the easy part where this script was concerned.
The applescript waited to
get a report back from the eFax shell script

So I had a whale of a time trying to figure out ways of forcing it to let go.
Any way here's the script which works.
I think personally I like the other one more. ( mainly because you don't get a fax beep at the start )

Code:

global thePID
using terms from application "Address Book"
        on action property
                return "phone"
        end action property
       
        on action title for p with e
                return "Dial using Landline"
        end action title
       
        on should enable action for p with e
                return true
        end should enable action
       
        on perform action for p with e
                set phone_num to the value of e
               
                -- Clean up the number from any extraneous characters
                -- like blanks, '(', ')', '-' .
                set phone_num to replace_chars(phone_num, "-", "")
                set phone_num to replace_chars(phone_num, "(", "")
                set phone_num to replace_chars(phone_num, ")", "")
                set phone_num to replace_chars(phone_num, " ", "")
               
                -- See if number already starts with '+'
                if phone_num starts with "+" then
                        -- If not, prepend "0" to the number and remove the +44
                        set phone_num to "0" & characters 4 thru -1 of phone_num
                       
                end if
                land_out(phone_num)
        end perform action
       
end using terms from

on land_out(phone_num)
        ignoring application responses
               
                tell application "Finder"
                       
                        set thecall to do shell script "efax -v0 -d /dev/cu.modem -a TDT" & phone_num
                end tell
        end ignoring
       
        set thePID to do shell script "ps acx |grep -i efax | awk {'print $1'}" as string
        display dialog "When you Hear Dialing choose" buttons {"Disconnect", "Pick-Up Handset"} default button 2
        if the button returned of the result is "Disconnect" then
                do shell script "kill " & thePID
               
        else
                delay 2 -- appx time it takes to pick up phone after hitting pick up button
                do shell script "kill " & thePID
        end if
       
end land_out


on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars


hayne 01-08-2006 06:35 PM

Glad you've got it working.
I note that there is another current thread on the same topic:
http://forums.macosxhints.com/showthread.php?p=260629

mark hunte 01-08-2006 06:37 PM

Cheers....

khedron 01-09-2006 02:48 PM

Hey mark,

looks like we're both working on the same thing at the same time. Check out my topic, which hayne posted a link to, for more tips... in particular, you can try this, which will dial the number, then automatically close efax without beeping and without having to kill the process manually:

Code:

try
        do shell script "/usr/bin/efax -d /dev/tty.modem -t '" & phone_num & ",;h0'"
end try

The user just has to pick up the phone within 2 seconds of the dialing finishing.

mark hunte 01-09-2006 03:25 PM

Thanks , That works.

Although I think for me I prefer the dialogue Asking.

One reason. I do not want to pick up an engaged line.
One odd thing.

I can run your script as:
Code:

try
        do shell script "/usr/bin/efax -d /dev/tty.modem -t '" & phone_num & ",;'"
end try

And it works the same. Most likely the try statements are helping that.

Also note if you do not have DT (Dial Tone) in the do shell script, you will need to append it to the number: i.e DT02075551234

How well does it work when in the full applescript

arielfr 07-12-2006 10:51 AM

Using 'screen' to dial
 
Greetings!

After much research, experimentation and some help from a user group, I've managed to get the 'screen' command to work as a dialer. I modified Mark Hunte's excellent dialer script (thank you Mark!) to implement it.

Although the script works well and reliably (iMac Core Duo), I'm concerned that my (almost total) lack of knowledge of Applescript has caused me to leave out something important. Could I therefore impose on the experts here to correct my changes? I'd much appreciate it!

In Mark's "autodialer1_scpt.txt", I replaced the "land_out(phone_num)" call with a call to "dial_via_modem(phone_num)", which follows below.

Code:

on dial_via_modem(phone_num)
       
        -- create detached "screen" session (-d -m) named "phone" (-S) to appropriate modem
        do shell script "screen -d -m -S phone /dev/cu.usbmodem"
        -- dial the number; command line is: screen -S phone -X eval 'stuff "atdNUMBER\015"'
        -- send the string (-X stuff) to screen 0 (-p 0) of session "phone" (-S)
        -- 'eval' command and single quotes are necessary to send the newline char (\015)
        do shell script "screen -S phone -p 0 -X eval 'stuff \"atd" & phone_num & "\\015\"'"
       
        -- show dialog with message and OK button and wait for keypress
        display dialog "When you hear ringing, pick up phone and click OK" buttons {"OK"} default button 1
       
        -- hang up modem
        do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
        -- and close session
        do shell script "screen -S phone -p 0 -X kill"
       
end dial_via_modem

Thank you very much!
Ariel

mark hunte 08-27-2006 05:58 AM

Another Poster in this thread drew my attention back to this thread.

Firstly Thank you arielfr for taking the time to look at and solve the screen dialing. Great job.

The script below is the evolved result of this thread so far.

Slight change to arielfr's script.

1, where you find the line

do shell script "screen -d -m -S phone /dev/cu.usbmodem"

Change
cu.usbmodem

to
cu.modem
if you use an internal modem.

2, I added the small change of atdt instead of atd
Doing this insured the modem is setup for 'Tone'
with just atd you will hear a lot of loud pops and clicks instead of a Dialing and ringing tone.

installing
Copy the script below and paste it into a New Script Editor Document (window).
Click the 'Compile' button.
Go to the 'File menu' and select 'Save'
Press the keyboard keys
shift+cmd+G which brings up the 'Go to Folder' menu option

enter this line:
~/Library/Address Book Plug-Ins

if you think you have a reason you can use then use this line instead.

/Library/Address Book Plug-Ins/

Click the 'GO' Button.

Give your script a name in the 'Save As' text box keeping the .scpt at the end.
Click the 'Save' button.

If Addressbook is running quit it, and then relaunch it.

Now when you click a number Tab you will see the 'Dial using LandLine' option

Good luck...

Code:

(* use /dev/cu.usbmodem  if you are using one
do shell script "screen -d -m -S phone /dev/cu.usbmodem"
or
/dev/cu.modem
if you are using an internal modem

*)

using terms from application "Address Book"
        on action property
                return "phone"
        end action property
       
        on action title for p with e
                return "Dial using LandLine"
        end action title
       
        on should enable action for p with e
                return true
        end should enable action
       
        on perform action for p with e
                set phone_num to the value of e
               
                -- Clean up the number from any extraneous characters
                -- like blanks, '(', ')', '-' .
                set phone_num to replace_chars(phone_num, "-", "")
                set phone_num to replace_chars(phone_num, "(", "")
                set phone_num to replace_chars(phone_num, ")", "")
                set phone_num to replace_chars(phone_num, " ", "")
               
                -- See if number already starts with '+'
                if phone_num starts with "+" then
                        -- If not, prepend "0" to the number and remove the +44
                        set phone_num to "0" & characters 4 thru -1 of phone_num
                       
                end if
                land_out(phone_num)
        end perform action
       
end using terms from


on land_out(phone_num)
       
        -- create detached "screen" session (-d -m) named "phone" (-S) to appropriate modem
       
       
        do shell script "screen -d -m -S phone /dev/cu.modem"
        -- dial the number; command line is: screen -S phone -X eval 'stuff "atdNUMBER\015"'
        -- send the string (-X stuff) to screen 0 (-p 0) of session "phone" (-S)
        -- 'eval' command and single quotes are necessary to send the newline char (\015)
        --do shell script "screen -S phone -p 0 -X eval 'stuff \"atl3\\015\"'"
        do shell script "screen -S phone -p 0 -X eval 'stuff \"atdt" & phone_num & "\\015\"'"
       
        -- show dialog with message and OK button and wait for keypress
        display dialog "When you Hear Dialing choose" buttons {"Disconnect", "Pick-Up Handset"} default button 2
        if the button returned of the result is "Disconnect" then
                -- hang up modem ( may be engaged )
               
                do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
                -- and close session
                do shell script "screen -S phone -p 0 -X kill"
               
               
        else
                delay 2 -- appx time it takes to pick up phone after hitting pick up button
               
               
                do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
                -- and close session
                do shell script "screen -S phone -p 0 -X kill"
        end if
       
end land_out
-- Text replace function
on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars


imacosxhints 08-30-2006 05:45 AM

well, guess i'm an unter-novice cause can't make it work... :(

ok well it ALMOST WORKS!

i did as told and indeed have the modem dialing with landline option upon control-clicking AB. but when i dial the tone is occupied.
what i forgot to mention is that i need a "0" prefix to have an outbound call... where should i correct this in the script?

last (but not least), i live in Europe, so does this mean that other parameters for landline dialing must be taken into consideration?

thanks in advance

mark hunte 08-30-2006 12:54 PM

Show me the structure of a number:
i.e is it :002071231234
you need.

Do you dial 0 wait for a tone and then 02071231234

explain ??

imacosxhints 08-31-2006 04:10 AM

well, a national number would look like this:

0, (prefix for any outbound call) 04 70 30 55 70

thanks!

mark hunte 08-31-2006 04:22 AM

Ok can not test this just yet.
but see if this works for you, where the line in the script is

do shell script "screen -S phone -p 0 -X eval 'stuff \"atdt" & phone_num & "\\015\"'"

change it to:

do shell script "screen -S phone -p 0 -X eval 'stuff \"atdt0," & phone_num & "\\015\"'"

Note the change is atdt0,

imacosxhints 09-11-2006 07:48 AM

well, it doesn't work and seems to block pagesender as it seems to continuously occupy the modem... :(

mark hunte 09-11-2006 06:33 PM

It works on my PB and another that a friend has with no tweaking needed.
Both G4 PPC (as in not intel ) PB's

I suspect that part of the problem may be apps on your mac jostling for control of the modem.
And your line setup.

It may help if you give a run down of your complete set up.

Cheers.

imacosxhints 09-14-2006 04:43 AM

well, running G4 pb 1,67 Ghz with 10.4.7. & 1,5 gigs of ram
using pagesender for sending faxes. No other app uses the modem

mark hunte 09-14-2006 05:23 AM

Can you turn Pagesender off and try.
Also did you do the change I suggested.

Give me step by step of what happens.

dilgreen 10-17-2006 10:46 AM

Thanks!
 
Thank you, Mark Hunter and Arielfr.

Just followed your combined procedure, and it worked first time, all fine and dandy! Wonderful to be able to piggy back on your smarts!

Cheeky follow up: do you have any idea why OS10.4 / G4 quicksilver won't pick up an incoming fax (all vanilla set up, System prefs control panel setup just as the 'help' pages tell you to). Sending is fine, so I know the line/modem etc works.

ingenious 11-28-2006 10:03 PM

Well, the script is wonderful! Thank you for building it. My problem is that most of my numbers do not have the necessary "1" in front of them. Is there something I can append to the script to have it check before dialing for the 1 and add it if necessary?

mark hunte 11-29-2006 02:02 PM

Quote:

Originally Posted by ingenious (Post 337919)
Well, the script is wonderful! Thank you for building it. My problem is that most of my numbers do not have the necessary "1" in front of them. Is there something I can append to the script to have it check before dialing for the 1 and add it if necessary?

This should check your USA number
if the number is example : 123456-1234

it will add 01 so the number will change to 011234561234

if the number is : 1123456-1234
it will add 0 so the number will change to 011234561234

if the number is : +1123456-1234

it will add 0 and remove the + so the number will change to 011234561234

if the number is : 01123456-1234

only the - will be removed, it will change to 011234561234

Code:

(* use /dev/cu.usbmodem  if you are using one
do shell script "screen -d -m -S phone /dev/cu.usbmodem"
or
/dev/cu.modem
if you are using an internal modem

*)

using terms from application "Address Book"
        on action property
                return "phone"
        end action property
       
        on action title for p with e
                return "Dial using LandLine"
        end action title
       
        on should enable action for p with e
                return true
        end should enable action
       
        on perform action for p with e
                set phone_num to the value of e
               
                -- Clean up the number from any extraneous characters
                -- like blanks, '(', ')', '-' .
                set phone_num to replace_chars(phone_num, "-", "")
                set phone_num to replace_chars(phone_num, "(", "")
                set phone_num to replace_chars(phone_num, ")", "")
                set phone_num to replace_chars(phone_num, " ", "")
               
                set counter to count characters of phone_num
                if counter is 11 then
                        set phone_num to "0" & characters of phone_num
                else if counter is 10 then
                        set phone_num to "01" & characters of phone_num
                end if
               
               
                -- See if number already starts with '+'
                if phone_num starts with "+" then
                        -- If not, prepend "0" to the number and remove the +1
                       
                        set phone_num to "0" & characters 2 thru -1 of phone_num
                       
                       
                end if
                land_out(phone_num)
        end perform action
       
end using terms from


on land_out(phone_num)
       
        -- create detached "screen" session (-d -m) named "phone" (-S) to appropriate modem
       
       
        do shell script "screen -d -m -S phone /dev/cu.modem"
        -- dial the number; command line is: screen -S phone -X eval 'stuff "atdNUMBER\015"'
        -- send the string (-X stuff) to screen 0 (-p 0) of session "phone" (-S)
        -- 'eval' command and single quotes are necessary to send the newline char (\015)
        --do shell script "screen -S phone -p 0 -X eval 'stuff \"atl3\\015\"'"
        do shell script "screen -S phone -p 0 -X eval 'stuff \"atdt" & phone_num & "\\015\"'"
       
        -- show dialog with message and OK button and wait for keypress
        display dialog "When you Hear Dialing choose" buttons {"Disconnect", "Pick-Up Handset"} default button 2
        if the button returned of the result is "Disconnect" then
                -- hang up modem ( may be engaged )
               
                do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
                -- and close session
                do shell script "screen -S phone -p 0 -X kill"
               
               
        else
                delay 2 -- appx time it takes to pick up phone after hitting pick up button
               
               
                do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
                -- and close session
                do shell script "screen -S phone -p 0 -X kill"
        end if
       
end land_out
-- Text replace function
on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars



All times are GMT -5. The time now is 06:03 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.