• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript-Users Digest - increase the performance of this script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest - increase the performance of this script


  • Subject: Re: AppleScript-Users Digest - increase the performance of this script
  • From: Mark Ratledge <email@hidden>
  • Date: Fri, 13 Apr 2012 13:33:29 -0600

>
> Date: Fri, 13 Apr 2012 09:07:24 -0600
> From: Mark Ratledge <email@hidden>
> To: email@hidden
> Subject: Script performance and Safari
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=us-ascii
>
> Is it possible to increase the performance of this script? It can take 3-4 seconds to run.
>
> I've saved it as a script instead of an application, and that has helped with the speed, esp. the shell script and the interactions with BBEdit. The main speed problems seem to be with Safari, and I know the UI scripting is problematic.
>
> Any ideas? Thanks
>
> ----------------------------------
> Mark Ratledge
> http://markratledge.com
>
>
>> tell application "Safari"
>> 	activate
>> 	tell application "System Events"
>> 		tell process "Safari"
>> 			click menu item "Select All" of menu "Edit" of menu bar 1
>> 			click menu item "Copy" of menu "Edit" of menu bar 1
>> 		end tell
>> 	end tell
>> end tell
>>
>> tell application "Safari"
>> 	set textclip to (the clipboard)
>> 	set theUrl to (get URL of document 1)
>> end tell
>>
>> try
>> 	set the clipboard to Unicode text of (the clipboard as record)
>> end try
>>
>> set dat to (do shell script "date '+%m/%d/%y' | sed -e 's/000$//' -e 's/^0//'") as string
>>
>> tell application "BBEdit"
>> 	activate
>> 	make new document
>> 	set text of front document to (dat & return & return & (theUrl) & return & return & textclip & return)
>> 	select insertion point 1 of contents of front document
>> end tell
>>
>> tell application "BBEdit"
>> 	activate
>> 	select text 1 of text window 1
>> 	straighten quotes selection of text window 1 with replacing target
>> 	select insertion point 1 of contents of front document
>>
>> end tell
>>
>
>>>
>>> ------------------------------
>>>
>>> Message: 4
>>> Date: Fri, 13 Apr 2012 18:10:19 +0200
>>> From: KOENIG Yvan <email@hidden>
>>> To: liste AppleScript US <email@hidden>
>>> Subject: Re: Script performance and Safari
>>> Message-ID: <email@hidden>
>>> Content-Type: text/plain; charset="utf-8"
>>>
>>> Try :
>>>
>>> tell application "Safari"
>>> 	activate
>>> 	tell application "System Events"
>>> 		tell process "Safari"
>>> 			keystroke "ac" using {command down}
>>> 		end tell
>>> 	end tell
>>> 	tell current application to set textclip to (the clipboard)
>>> 	set theUrl to (get URL of document 1)
>>> end tell
>>>
>>> try
>>> 	set the clipboard to (the clipboard as Unicode text)
>>> end try
>>>
>>> set dat to (do shell script "date '+%m/%d/%y' | sed -e 's/000$//' -e 's/^0//'") as string
>>>
>>> tell application "BBEdit"
>>> 	activate
>>> 	make new document
>>> 	set text of front document to (dat & return & return & (theUrl) & return & return & textclip & return)
>>> 	select insertion point 1 of contents of front document
>>> 	select text 1 of text window 1
>>> 	straighten quotes selection of text window 1 with replacing target
>>> 	select insertion point 1 of contents of front document
>>> end tell
>>>
>>> Just a question :
>>> Why are you converting the clipboard's contents to Unicode and insert the original contents in the created document ?


That is a bit faster, thanks. I ended up with this:


tell application "Safari"
	activate
	tell application "System Events"
		tell process "Safari"
			click menu item "Select All" of menu "Edit" of menu bar 1
			click menu item "Copy" of menu "Edit" of menu bar 1
		end tell
	end tell
	tell application "Safari" to set textclip to (the clipboard)
	set theUrl to (get URL of document 1)
end tell


set dat to (do shell script "date '+%m/%d/%y' | sed -e 's/000$//' -e 's/^0//'") as string

tell application "BBEdit"
	activate
	make new document
	set text of front document to (dat & return & return & (theUrl) & return & return & textclip & return)
	select insertion point 1 of contents of front document
	select text 1 of text window 1
	straighten quotes selection of text window 1 with replacing target
	select insertion point 1 of contents of front document
end tell



This line greatly speeds it up, but doesn't want to work:

keystroke "ac" using {command down}

It selects all the text but doesn't copy it to the clipboard. So I stayed with

click menu item "Select All" of menu "Edit" of menu bar 1
click menu item "Copy" of menu "Edit" of menu bar 1

I did get rid of the unicode text line.

-- Mark
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: AppleScript-Users Digest - increase the performance of this script
      • From: KOENIG Yvan <email@hidden>
  • Prev by Date: Re: Script performance and Safari
  • Next by Date: Re: AppleScript-Users Digest - increase the performance of this script
  • Previous by thread: Men’s health and Viagra
  • Next by thread: Re: AppleScript-Users Digest - increase the performance of this script
  • Index(es):
    • Date
    • Thread