Hi, I am a Billy basic user with no programming experience but am great with copy and paste
Can any of you experts help me please?
I am trying to save my poor wrists from RSI by limiting the mouse dragging and clicking, I am harvesting school names, telephone numbers and email addresses from state web sites, I can do the auto copy and paste into Excel and then back to Safari but what I can't do is automate the mouse selection process.
The school names, telephone numbers and email addresses are in similar positions but never exact so the record function doesn't work for me. I thought I may be able to manually click at the beginning of the line and get Maestro to hold the mouse key down and have it drag to a certain position and then release and copy and paste into Excel, but I can't see how to do that. The end of the line is always the same. Does this make sense?
Please see the link for an example of one of the pages.
You'd then have the name, the phone and the email in three KM variables, that you can easily use later to insert the text in Excel, with something like that (assuming you put the cursor into the Name cell and Phone and Email are next to it):
How it works:
If you look at the source code of the page (for example by right clicking on a school name and selecting Inspect Element—assuming you've enabled the Develop menu in Safari), you can see that the various fields are enclosed in a div whose class is named estabContent:
<div class="estabContent" >Albourne CofE Primary School (Hassocks)</div>
Hopefully that should get you started. And if you feel like learning more about controlling Safari or Chrome from KM, you can see my tutorials at http://flipmartin.net/software .
Wow! Thank you very much for that, but you lost me at Hi! (Almost)!
The Uk schools sites are all different, I have just finished doing the West Sussex one manually. I can see how your solution would be perfect if my knowledge was even 1% of yours, is there a way to do it via the muse for the other sites without looking at the source code? Thank you very much for your time anyway.
Oh, I thought you extracted that info from a single site, sorry. Unfortunately that method won't work if each school has its own site, unless they're all made by the same organism on the same model and using the same templates.
Click and drag will probably never do it, because you have to give it coordinates, and they'll always change. But maybe triple-clicking would do. If you try triple-clicking the value of one field, like the address, on the site you referenced, it will select the contents of that field (except if the whole contents of that field is a link). So maybe you could base your macro on that. You can have KM do a triple-click where your cursor is that way:
wait for you to press Return (which you'd do after you moved the cursor over the next field to extract)
copy the selection
put the clipboard into another variable
wait for you to press Return again
and so on.
That wouldn't be as easy or quick as my original suggestion, but it would still be better than doing it all by hand, as you'd just have to trigger the macro, then move the cursor and press a key a few times.
Thats amazing Philippe, I had no idea that a triple click existed (told you I was a billy basic), I can even triple click slightly to the right of the hyperlinked email addresses and it highlights the whole email address without opening it - my wrists are saved. Now comes the “trying to explain to one half of the thicky twins the theory of relativity” bit, the variables mention is having me stumped. So i move the mouse to where I want the fantastic Keyboard Maestro to triple click (school name), command C to copy it then do the variable bit, go to the school telephone number, repeat it and then go to the email and do the same, open excel and how do I paste the three separate bits into lateral cells? sorry that I am trying your patience. x
Copy and paste is often quite problematic from Safari. If you feel you must c&p then Firefox will probably give you more consistent results.
Personally I would automate the heck ouf of this job by pulling the text out of the page in Safari, processing it, and then putting it into Excel.
This the attached example macro is specifically tailored for the link you provided to show how a little processing can go a long way - but it can easily be made more generic.
You start out by loading the page you want to process in Safari and then run the macro.
I'm using TextWrangler (freeware) as the output vehicle for the text, because it's very scriptable and therefore fairly ideal for secondary processing. (I use TextWrangler's commercial sibling BBEdit myself.)
The shell script in the macro assumes you have TextWrangler installed along with its command-line-tools. (Command-line-tools are installed via the TextWrangler menu in the app.)
The output of the macro looks like this:
Albourne CofE Primary School (Hassocks)
Mrs. A Sturgoen
Chair of Governors:
Mr. M. Cutress
23 - Hassocks
Area Partnership C2
Primary (Years R to 6)
And that's pretty easy to work with.
For practical usage I'd let the whole text be sent to TextWrangler and do all processing in it with a filter or two.
If you want to give this a try I can help you with some general filters.
P.S. Bah! I forgot to add an attribution comment to the macro.
Hi Chris, thank you very much for taking the time and effort to reply with your solution, I am learning so much here. However your variable and shell script bit has gone so far over my head I think the international space station may now be able to see it.
I have downloaded and installed Textwrangler, I have made a simple macro (and i mean simple) to click on a link and then copy the whole of that web page into text wrangler, It seems a shame, that now I have everything, not to extract more than just the school name, email and telephone details, the full address, Head teachers name and DFE number would also be very helpful - I could then put it all in a excel sheet to use better. How would I use textWrangler to remove the chaff to be left with those bits and then export that into single cells across the sheet? Hopefully once I manage to learn from you gurus I can use these methods on all the other County websites. Tony
On another point, when i copy and paste and do other multiple things, my mac seems a tad too quick which gives me erratic results, I have just found the pause control and add .1 second pauses everywhere but this seems a bind, am i missing something? this is particularly noticeable when i copy and paste 10 email address from excel and put them into the bcc field in outlook…
Hey Chris, I found this looking for a somewhat unique version of this. Precisely this, but having the HTML be HTML on the clipboard (Text Factory before pasting would be EXTREMELY HELPFUL), but I need it to paste into BBEdit or Numbers as the final very much trimmed down pieces I derive from the text Thank you if you're able to help in advance!