Missing Periods

I have a very simple script (modified from one I found here or somewhere like here) that sends me a mail of the URL in a Camino page. It works fine on my G4, running OS X 10.4.5. It also runs fine on my G3 iBook running the same OS, and exact same software, except that it strips the periods from the e-mail address. Thus, “blah@mac.com” becomes “blah@maccom”. So, I get a postmaster’s message each time I use it on the iBook. It works in that I CC and so get the information I want. But…

What can it be? I’ve re-typed, copied and pasted, input from the character palette, and everything. In mail addresses with several periods, it strips them all. I’ve tried a longer delay for the slower machine.

I run Japanese as a secondary language on my machines, but the two are set up identically. Anyway Japanese mail addresses are the same.

Any ideas?

tell application “System Events”
tell application “Camino” to activate
tell process “Camino” to keystroke “l” using command down & shift down
delay 1
keystroke “blah@mac.com
keystroke tab
keystroke tab
keystroke “Web Address”
keystroke “d” using command down & shift down
delay 1
keystroke “h” using command down
end tell

Model: Macs
AppleScript: 1.10.3
Browser: Camino 1.0
Operating System: Mac OS X (10.4)

On the machine that fails, try inserting

set AppleScript's text item delimiters to ""

just ahead of your tell block.

Thanks for the idea. Unfortunately, it didn’t make any difference. I don’t understand this problem, because all the other keystrokes are fine, including the @. Simply the period disappears. Oh, and I tried putting punctuation in one of the later entries, to see if it was something to do with the address field in Mail. Other punctuation works fine - apostrophe, question mark - but any period disappears.

This works for me, though I must confess, I don’t know how or why:

tell application "System Events"
	tell application "Camino" to activate
	tell process "Camino" to keystroke "l" using command down & shift down
	delay 1
	keystroke "blah"
	keystroke "@mac"
	keystroke ".com"
	keystroke "d" using command down & shift down
end tell

In Eudora, the original didn’t miss periods, but it did occasionally miss a character. Breaking it up like this seems to work,

I like this script, and obviously, it needs tweeking, depending on the mailer. For Eudora 6 this works, putting the address specified in To: and the URL of the frontmost Camino tab in the body of the text as a link.

set Txt to characters of text returned of (display dialog "To Whom?" default answer "adam@somewhere.net" buttons {"Cancel", "OK"} default button "OK")
set C to (count of Txt)
set T to {}
set text item delimiters to "" -- for some reason this script screws them up occasionally
try
	repeat with k from 1 to C by 4
		set end of T to items k thru (k + 3) of Txt as text
	end repeat
on error
	set TC to count of T
	set end of T to items (4 * TC + 1) thru -1 of Txt as string
end try

tell application "System Events"
	tell application "Camino" to activate
	tell process "Camino" to keystroke "l" using command down & shift down
	delay 0.5
	repeat with k from 1 to TC + 1
		set P to (item k of T)
		keystroke P
		delay 0.25
	end repeat
end tell

Thanks again.

I tried both of these ideas, and they work, except that when the address is posted into Mail, the period disappears. In the longer script above the OK/Cancel box shows the address correctly, but the post into mail doesn’t work. It’s just the period. In all addresses, the periods go, but I can put in any other punctuation I like and it’s fine. And it works nicely on the G4. I can’t think of any differences between the machines’ set-up. They’re both mine and intended to be substitutes for each other.

In case you wonder why I want this script:
I really like the new Camino v1 and want to use this as my main browser rather than Safari. However, I regularly copy and save parts of articles I read as rtf files. I want to preserve the formatting. Camino/Gecko won’t do this. Also Camino won’t save as webarchive. So, my idea is to send the url of pages I want to save to myself. When I’ve finished reading in Camino, I open my mail. Safari is the default browser. I open the link, select the text I want, and then click on an automator action (which is mainly Applescript) which copies the text, opens a TextEdit document and pastes the text. I give it a name and save. So two clicks. It’s actually smoother than my old method of copying and pasting manually from Safari as I read (the reading isn’t interrupted), and the delay before the pasting stage gives me time to think ‘Do I really want to save this?’

Since on the iBook I always copy to myself all mail sent (so I can consolidate mail on the G4), I get the address even with the broken script. It’s just a psychological thing. All those postmaster mails!

MacNara. Forgive me if you’ve already thought of this, but can Camino paste directly into TextEdit using the menu sequence “Camino”->“Services”->“TextEdit”->“New Window Containing Selection”? If so, it could save you having to use e-mail at all:

tell application "TextEdit" to launch

tell application "System Events"
	tell application process "Camino"
		set frontmost to true
		click menu item "New Window Containing Selection" of menu 1 of menu item "TextEdit" of menu 1 of menu item "Services" of menu 1 of menu bar item 2 of menu bar 1
	end tell
end tell

-- Name and save the TextEdit document.

Yes, it will, but my problem is that Camino will not copy formatted text, which is what I need. If Camino would do this, then I could use the Automator script I made to paste from Safari to do it directly from Camino.

The director of the Camino project told me that Camino is not likely to be able to do this in the near future.

If anyone can tell me how to paste text from the clipboard into the message area of a new mail in Automator, then I can send a message to myself from Automator. At the moment, I can only send empty messages or attachments, which is useless.

If you can get the url from Camino’s front page/tab, then Mail can probably do the rest for you without involving UI scripting. This is how I might approach it using Safari/Mail:

tell application "Safari" to set c to front document's URL
tell application "Mail" to tell ¬
	(make new outgoing message with properties {subject:"Web Address", content:c})
	make new to recipient with properties {address:"me@mac.com"}
	send
end tell

It’s significantly faster and cleaner than UI scripting - with the added bonus that, throughout the execution of the script, neither the browser nor Mail needs to be frontmost (or, for that matter, even visible).

By taking a slightly different approach, the risk of tid troubles could be avoided altogether, Adam. In addition, direct text manipulation is faster than creating lists of characters and then coercing them back to text.

To demonstrate, here’s a slightly tweaked version of the first part of your script:

set txt to text returned of (display dialog "To Whom?" default answer "adam@somewhere.net")
set c to count txt
set t to {}
repeat with k from 4 to c by 4
	set t's end to txt's text (k - 3) thru k
end repeat
if k < c then set t's end to txt's text (k + 1) thru c

-- etc...

Well, I really appreciate you all taking the time to think about my problem. Please don’t be angry that I’ve decided to take a slightly different route. As you will have realised, I am an absolute Applescript beginner. Thanks to your encouragement, I have got where I wanted (I think) and I feel I’ve achieved something, even though it’s trivial by your advanced standards.

(The original problem and reason for wanting to write the script is in a previous post.)

When I first realised that Camino was lovely to browse with, but not good for my saving needs, I thought I’d use Automator. I’ve been using Macs for nearly twenty years because they’re “easy to use”. I recall Steve Jobs’ MacWorld presentation of Automator and thinking, “That looks easy and useful.” But it isn’t, and the couple of things I thought I might do, I couldn’t.

When I tried to write an Automator script to do what I wanted here, I discovered you can copy to the clipboard, but there’s no action ‘paste from clipboard’. You have to put an Applescript step in to do this, I found after a couple of hours on the Intenet. Anyway, I eventually tracked down an Applescript which did more or less what I wanted, and adapted it for Camino. Then I wrote an Automator script which is also mostly Applescript, to get my stuff with formatting from Safari to TextEdit. The pair worked fine on the G4, but the periods in the mail address didn’t appear on the iBook.

So, after the patches Adam Bell suggested didn’t work, I went back to Automator, and tried to find a way to get the clipboard contents to the message area of a new mail. Eventually, I realised that if I pasted into TextEdit (an Applescript step), and then used the Automator Action ‘Get Contents of Text’, I should be able to do this. I had to get an action (Create Mail Message) I found at an Automator site on the Internet to get the text into Mail (New Mail Message, the Apple action, wouldn’t do this).

It then occurred to me that it would be nicer to get one mail with all the urls, instead of one mail for each. So I wrote an Applescript to append a url to a text file (it took me two hours on the Internet to find out how to put a return into TextEdit - Apple’s online help for their own product being, as usual, just a long advertisement for the product and useless as help). I append the script below.

Then I wrote an Automator script to send the text by Mail. The only reason for sending to Mail is that inside a mail the urls are now linked to the sites, whereas in TextEdit, they are just text.

Although it sounds a bit of a mess (with one Applescript application and two Automator applications), it’s nice to use.

I use Camino to browse - it’s really smoother, and nicer to look at than Safari, and it handles adverts and Javascript better.

The script to save the links (below) is quick, and almost invisible. My reading is almost uninterrupted by copying, pasting, etc,

The send to mail Automator application is also quick, and gives me one page with links.

During the ‘select’ phase, I can review my choices, whereas before I saved everything I might want ‘just in case’.

I still have the Automator application to copy the selection from Safari, and paste it with formatting into TextEdit in one click.

I have to wonder how beginners to Mac react when they realise how complicated some of the ‘easy’ things are. I’ve used Macs for a long time, and I’m not innumerate, or put off by code - simply I have never done it because I’ve never needed to. It’s taken me two full days to get this far. I hope Apple don’t upgrade Safari so I like it more than Camino!

So, thanks again.

Here’s what I finished up with:

tell application "System Events"
	tell application "Camino" to activate
	tell process "Camino" to keystroke "l" using command down
	tell process "Camino" to keystroke "c" using command down
	tell application "TextEdit" to activate
	tell process "TextEdit" to keystroke "v" using command down
	set process "TextEdit"'s frontmost to true
	keystroke return
	keystroke return
	tell process "TextEdit" to keystroke "h" using command down
end tell

How about just doing a script that does this:

  1. Get the URL of the current page in Camino
  2. Open that URL in Safari
  3. Copy&paste the contents in TextEdit and Save

Thank you for that lesson, Kai - when I had tried that approach last night (grabbing the text instead of the characters) then later on in the process, I was getting unwanted returns. Eventually, I figured out that the delimiters were screwed up, but by then had moved on to the “characters” solution. Yours is much neater. Another failure in my approach was in depending on the chunk grab to error in order to get the rest. Repeating from 4 to C by 4 falls out automatically and the if k<c does the rest. Clean.

I should say that I don’t really need this - I would be inclined to do it differently too - but I wanted to see if I could make it work.

I can’t use one script to do all three steps because I don’t want to save all of any page - I don’t want the ads, any frames or headers and footers, and not the back to the top and home buttons. I have to select the bit I want to save by manually dragging and clicking; it can’t be automated. I want to keep any formatting in the bit I save - e.g. headline fonts in newspaper articles, and embedded webpage links - but I don’t want this other stuff. And I want to minimise the number of steps, and to concentrate on reading as much as possible without long timeouts for saving. If I read in Safari, I could arrange it better, but I really like the new Camino enough to make the effort to do it this way.

And the way outlined above - i.e. with these three scripts - is more efficient psychologically and physically than reading, saving, reading, saving, especially compared with the 100% manual method I was using before. All the reading is now done in one stage, and all the saving in another. I can review my saving choices, and I can put off the saving part until another day if I’m busy. I’m happy.

Thanks to the people who responded above, I was encouraged to try hard to get it right, and in the process I found a method of work that suited me better. And I will certainly try to use Applescript again. So, although the advice people gave wasn’t directly used, it still had a positive effect, and I’m grateful.

MacNara

As I mentioned, I do the same thing very differently: I use an application called StickyBrain, which has a contextual menu for doing exactly what you want. Select the part you want, right (or control) click, StickyBrain grab to, select where to put it in a cascading menu. I should add that I’m just a fan; I’m not involved in any way with the authors.

Yes, I know there are various ways of doing things. However with the three scripts I think I have about the minimum number of mouse actions compatible with what I want to do - single clicks, not double clicks if I put the script icons in the dock (which is on the right, so gives me a natural action, and means the icons don’t get hidden by the windows).

#Think I might want to save something in a page? Click the ‘Camino Text’ icon [page url is added to a text file].

– Want to add a comment to the url? Bring TextEdit to the front and do so.

#Want a clickable list of all the pages to view? Click the ‘Text Mail’ icon (Automator/Applescript) [list of all the urls goes to one mail, for viewing anytime. Has a headline telling me what it is, and a dateline, so I know which day I picked these items out].

#Want to save something with formatting? Click on the link in Mail [page opens in Safari], select what I want, and click ‘Safari Text File’ (Automator/Applescript) [Text Edit file opens, the selection is pasted in, and the Save as dialogue opens]. Give it a name and close.

With an application like Sticky Brain, if you are regularly saving different types of data to different places, then I think it would be useful. In my case, I use exactly the same applications, and do exactly the same things, forty or fifty times a week maybe, so dedicated scripts will be best. If you think about doing what I do manually, there are a lot of keystrokes (open application, copy, paste, save as, etc) and a lot of switching between mouse (selection and clicking) and keyboard. Now I can browse with just the mouse, and save stuff with a lot less effort. It fits into my workflow better than Sticky Brain would, I think. Sticky brain would only do the Safari portion of the work, and anyway I can get to the save dialogue in one click with my method, which I think is the quickest possible.

I wish I’d made more of an effort to do this when I was just using Safari; even without the Camino business, it would have been a timesaver.

I’ll surely look to use Applescript again, and without your replies, I would probably have given up. Thanks.

Hi,

It’s been a while since I tried Camino and I like it now! I think there is a way to get the formatted text, but it’s a long workaround. First you may be able to save the page as pdf. Then you may be able to copy the text. Personally, I’d just save the pdf.

Here’s to Caminoing!

Salute to the Presidents.

gl,