Macworld Forums

Macworld Forums: Automator Power: Variables and looping - Macworld Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Automator Power: Variables and looping

#1 User is offline   Macworld 

  • Story Poster
  • Group: MW Bot
  • Posts: 34,402
  • Joined: 30-November 07

Posted 07 January 2008 - 02:00 PM

Post your comments for Automator Power: Variables and looping here
0

#2 User is offline   mooncaine 

  • Member
  • PipPip
  • Group: Members
  • Posts: 99
  • Joined: 29-June 06

Posted 08 January 2008 - 05:40 PM

Does Automator finally include an action that will simply copy selected text from a web page?

I wanted to make several Automator actions that were impossible [as far as I could tell] because I could find no way to get Automator to copy the selected text from a web browser. There's a great little addon for Firefox that copies whatever text I selected, on a web page, and pastes into a TextEdit document, then adds the URL of the same page, and the title [from the HTML title tag]. I wanted to make one for Safari for years, but can't find a way [I'm now using OSX Tiger] to get Automator to copy the text selected on a Safari web page.
0

#3 User is offline   bwaldie 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 09-January 08

Posted 09 January 2008 - 10:21 AM

Automator includes an action called "Get Text from Webpage", which will extract all text from a web page. There's currently not an action available that will get just the selected text.

You may, however, be able to accomplish this in Leopard using Automator's record function. You could try clicking record, going into Safari, and choosing copy from the Edit menu (or typing Command+C). Then, you could play the recorded steps back as part of a larger workflow.

You may also want to browse third-party actions, to see if someone has created an action that will extract selected text from Safari. I'm not aware of one, but you could start by checking...

Apple's Mac OS X Downloads Site
MacScripter's Automator Actions
Automator World

Hope this helps.

-Ben
0

#4 User is offline   musselrock 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 14-January 08

Posted 14 January 2008 - 01:42 PM

I Don't know about Automator, but AppleScript will do what you want.

The example below will get Safari's selected text and plop it on to the end of a text file sitting on the desktop (or create the file if it does not exist).

--START SCRIPT--
tell application "Safari"
set selecTxt to ((do JavaScript "unescape(getSelection())" in document 1) as text)
set theurl to ((get URL of document 1) as text)
set pgTitl to (do JavaScript "document.title" in document 1) as text
end tell

set dat to (current date) as text
set clipFil to (path to desktop folder as text) & "SafariText.txt"
try
close access file clipFil
end try
set filRef to open for access file clipFil with write permission
write (dat & return & (theurl) & return & (pgTitl) & return & "-------------------" & return & selecTxt & return & "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & ?
return & return) to filRef starting at eof
close access filRef
tell application "Safari" to activate
--END SCRIPT--

I run this script as an application. It is positioned on the extreme left side of the desktop so that I can just see part of the name poking out behind Safari's window. A double click does the job and puts me right back into Safari almost too quickly to notice.

--EXAMPLE OUTPUT--
Monday, January 14, 2008 12:54:35 PM
http://www.macworld....geekfactor.html
Macworld | Automator Power: Variables and looping
-------------------
mooncaine says:
Tue Jan 08 17:40:35 PST 2008
Re: Automator Power: Variables and looping
Does Automator finally include an action that will simply copy selected text from a web page?

I wanted to make several Automator actions that were impossible [as far as I could tell] because I could find no way to get Automator to copy the selected text from a web browser. There's a great little addon for Firefox that copies whatever text I selected, on a web page, and pastes into a TextEdit document, then adds the URL of the same page, and the title [from the HTML title tag]. I wanted to make one for Safari for years, but can't find a way [I'm now using OSX Tiger] to get Automator to copy the text selected on a Safari web page.

Reply to this comment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--END EXAMPLE OUTPUT--

Alternately, just set the clipboard to the selected text by replacing

--THIS--
set theurl to ((get URL of document 1) as text)
set pgTitl to (do JavaScript "document.title" in document 1) as text
end tell

set dat to (current date) as text
set clipFil to (path to desktop folder as text) & "SafariText.txt"
try
close access file clipFil
end try
set filRef to open for access file clipFil with write permission
write (dat & return & (theurl) & return & (pgTitl) & return & "-------------------" & return & selecTxt & return & "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & ?
return & return) to filRef starting at eof
close access filRef

--WITH THIS--
set the clipboard to selecTxt
0

#5 User is offline   ax1973 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 23-December 10

Posted 23 December 2010 - 07:09 AM

help wanted help wanted.
hi there, if it is possible i need your help. I am new in mac world, and I'm enthusiast, but I need a quick solution for a problem I have. I want to learn applescript very well, or automator, because I need to do this automation, but I am in a hurry:
for example, I need to copy an entire text line like "my name is alex and i live in Italy" from an excel file document, paste the text into a webpage like google.com, click the search button on google, and if the entire line text appears in the results of google search, send me an email OR create a new text file where is present the text line I have searched and that google found. If the entire text line does not appear I don't need any email or text. And another thing is, if the first line I've copied is in the A1 cell of Excel for example, I need to create a loop that after the first search is finished, he copy the text present into the A2 cell, made the search on google etc etc, and after copy the text line present into the A3 cell etc etc etc.
It is possible? I think yes, but for me is too complicate and I am in a hurry! I have more than 2000 cells and I have only a few days!

Thank you and happy new year from Italy, I'm sorry for my bad english!
0

#6 User is offline   Helal 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 07-June 11

  Posted 07 June 2011 - 11:02 PM

Can I use Automator to create a variable and change its value, and do some task again and again corresponding to different values of the variable?

I have a document created in numbers. I have to input 1 in a certain cell and convert the file to pdf as Filename 1.pdf, then change the cell value to 2 (and so upto 200) and convert all those files as Filename x.pdf. Can someone guide me to do this? I have no idea about AppleScript or any other scripting. Thanks in advance.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users