• 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: Setting Safari's Homepage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting Safari's Homepage


  • Subject: Re: Setting Safari's Homepage
  • From: kai <email@hidden>
  • Date: Sun, 20 Mar 2005 23:23:42 +0000


On Mon Mar 14, 2005 7:53:04 pm Europe/London, email@hidden wrote:


Can I set Safari's homepage to a specific URL using an AppleScript?

Wading through my hefty backlog of digests, I didn't see a response to this, Jim - to which my answer would be a rather qualified "yes".


To my knowledge, there's no direct Apple Event that will achieve this. Safari relies somewhat heavily on the 'do JavaScript' command to achieve a variety of things. The java 'sethomepage()' command appears to be possible in IE but in little else. Even there, I believe restrictions are being introduced in response to the online hijacking of users' homepages via java.

As far as I can see, that leaves only a couple of realistic options: GUI scripting in Safari - or changing the preferences for the default browser.

The modification of some plist values can be relatively easy using shell defaults. Others (as in this case), where keys and their values are more deeply nested, may be more problematic. In addition, I understand that it's inadvisable to try changing plist values while the application concerned is running.

The following suggestion therefore uses GUI scripting when Safari is running and (vanilla) plist modification when it's not. (The script works fine here, but you might still like to consider storing a copy of your '/user/lib/prefs/com.apple.internetconfig.plist' file - at least until you've tested it for yourself):

---------------

property Safari : "Safari"

on enterVal for currVal
tell application (path to frontmost application as Unicode text) to set newVal to text returned of (display dialog "Please enter a new homepage (leave blank if required):" default answer currVal)
if newVal is currVal then error
newVal
end enterVal


to changeDefaultHomepage()
set f to (path to "pref" as Unicode text) & "com.apple.internetconfig.plist" as alias
set o to open for access f with write permission
set e to read o
set c to count e
set text item delimiters to "<key>WWWHomePage</key>"
set e to e's text from text item 2 to -1
set text item delimiters to "<string>"
set e to e's text from text item 2 to -1
set c to c - (count e)
set d to "</string>"
set text item delimiters to d
set h to e's text item 1
set e to e's text from text item 2 to -1
set text item delimiters to {""}
try
set h to (enterVal for h)
set eof o to c
write ({h, d, e} as string) to o
end try
close access o
end changeDefaultHomepage


to changeSafariHomepage()
tell application "System Events" to tell process Safari to if exists then
set frontmost to true
keystroke "," with command down
tell me to tell application Safari to set miniaturized of window 1 to true
tell window -1
if name is not "General" then tell tool bar 1 to click button "General"
tell group 1 to tell group 1 to tell text field 1 to try
set value to my (enterVal for value)
confirm
end try
click button 1
end tell
else
my changeDefaultHomepage()
end if
end changeSafariHomepage


changeSafariHomepage()

---------------

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Setting Safari's Homepage
      • From: kai <email@hidden>
  • Prev by Date: FileMaker 7 Container Fields
  • Next by Date: FileMaker Pro 5.5/OSX 10.3.8/QuickMqilPro 3.1
  • Previous by thread: Setting Safari's Homepage
  • Next by thread: Re: Setting Safari's Homepage
  • Index(es):
    • Date
    • Thread