Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
HI All,

I wanna write an applescript to change the Text Encoding under "View" menu,every time I open safari.

since it will automatically be reverted to "Default" every time I quit Safari (very retarded!!)

But I'm no guru of programming. I don't know how to click a sub-menu..

This is all what I know:
activate application "Safari"

tell application "System Events"

tell process "Safari"

click menu item "Text Encoding" of menu 1 of menu bar item "View" of menu bar 1
delay 1
{The next step will be clicking the encoding I want, e.g. : Western(IOS Latin 1)....but this is where I need you guys help!!}
end tell
end tell


Thanks a lot everyone!!!
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
Doesn't
Code:
Safari -> Preferences -> Appearance -> Default Encoding
allow you to change the default. :confused:

B
 

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
NO that's different

You can try on any website...

change the encode under view menu, go to the website, then quit safari, go the the website again...encoding reverts to default...

This is the bullcrap of mac...

and I;m trying to fix it myself
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
This is the bullcrap of mac...

Actually sounds to me a problem that the website is not correctly (if at all) declaring the text encoding being used.

BTW Have you tried other browsers. All the big browsers (except IE of course) are available for the Mac.
 
Last edited:

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Thanks for you guys response..

However,

1)

I want to modify encoding NOT because I can't read some webpage..
but I don;t want to read site in certain language...I wanna filter out these pages..

So, none of the websites biz...lol..

2)

I'm sticking to Safari, cuz' I hate Microsoft & stupid UI of firefox..So switch browser won't work here either...

All I'm asking is to make an Applescript to change text encoding every time I open the browser...(Refer to my first post)

Anyone??
PS:
For those who think change encoding under preference menu read this thread first : http://discussions.apple.com/thread.jspa?messageID=12563666
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
PS:
For those who think change encoding under preference menu read this thread first : http://discussions.apple.com/thread.jspa?messageID=12563666

The fine link said:
What the Default actually means is determined by what you put in Safari > Preferences > Appearance. Even when it says Default, Safari actually uses the encoding specified by the html code of a web page, unless there is no such code. Then it uses the Default.

FireFox is different and when you look at View > Text Encoding you will see the encoding of the page you are viewing instead of Default.

This is what we are saying. Default is what you tell it to be, but it is overridden by code from the website. Maybe the website in question has a preference/cookie of its own to change the language/encoding.

Can you tell us what website it is?

EDIT: Here's a link to a tutorial on scripting menu items if you absolutely have to "go there". http://www.macosxautomation.com/applescript/uiscripting/index.html

B
 
Last edited:

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Oh I see what you mean, sorry for the misunderstanding..

but it's not about any site..

even i change the encoding on google.com

next time i go to the page the encoding will still revert..

how frustrating is that....
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
next time i go to the page the encoding will still revert.

Why is that a problem. It reverts to the Default value you set in Preferences. (You define what Default is). I agree that it would be nice if it indicated what that was instead of "Default".

B
 

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Really, is that the way it is supposed to work?
Now I know what this twist is all about. Let me restate my case with more detail:
Let's take http://www.amazon.co.jp/ for example

I open safari preference, change the default encoding to, say Cyrillic, which obviously can't display japanese correctly.

Then I restart safari, open Amazon(JP), it reads japanese perfectly. Looks like Safari will detect encoding itself or somepin. i don't know if it just happens to me, but according to the post at the bottom of this , I seems this is how it's supposed to work.

Which means It does revert to default but NOT the default I set under preference but the application or system default which is, maybe uni-8 or Latin-1, I'm not sure, but sure it reads any language pretty smooth...

So I open a new page, goes to Amazon(JP), change the encoding to Cyr- under the view menu. The page won't display proper as I expected. But next time I open safari the encoding under View menu will revert, that's what Im saying. This explains why I need the applescript.....

SOS!!!!
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
This explains why I need the applescript.....

No it doesn't, because you are obviously not trying to view amazon.co.jp in Cyrillic.

The source for amazon.co.jp includes many references to
Code:
encoding=UTF8
So when you go to amazon.co.jp that is what is respected.

This is why we were blaming the website you are trying to visit, obviously not amazon.

B
 

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Can these be a proof?
screenshot20110110atam1.png
 

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Anyway, thanks a lot "balamw"..appreciate your help.

In the meantime, can anyone finish that applescript for me...even with the link(no examples), I'm still having problems get it done..

sigh....
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
Anyway, thanks a lot "balamw"..appreciate your help.

In the meantime, can anyone finish that applescript for me...even with the link(no examples), I'm still having problems get it done..

sigh....


Here you go... This is the EXTREME longhand version of this, but it works.. Change the encoding in the middle buried line to the one you want:
Code:
tell application "Safari"
	activate
end tell

tell application "System Events"
	tell process "Safari"
		tell menu bar 1
			tell menu bar item "View"
				tell menu "View"
					tell menu item "Text Encoding"
						tell menu "Text Encoding"
							click menu item "Greek (Windows)"
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
Thanks ulbador.

Can these be a proof?

What I am missing is why that is desirable? If you set the default to "Cyrillic (Mac OS)" instead of "Western (ISO Latin 1)" in "Preferences -> Appearance" that will cause text that does not have a defined encoding to appear in your selected Default encoding.

In the case of Amazon.co.jp, most text is defined by the site to be in UTF-8 and should properly be represented as such. No?

EDIT: The blame still lies with whatever website you are using that isn't sending the proper charset with their pages.

If you
Code:
 telnet amazon.co.jp 80
GET /
You will find:
Code:
 <meta http-equiv="content-type" content="text/html; [B]charset=Shift_JIS[/B]" />
near the top of the reply.

(Similarly macrumors specifies:
Code:
<meta http-equiv="Content-Type" content="text/html; [B]charset=utf-8[/B]" />
)

Safari sees that and respects the website's wishes, but also gives you the option to override that after the fact if the website is poorly coded. (Which amazon.co.jp and macrumors are not).

What jiminaus and I are saying is that ultimately the problem lies with the website you are using sending the wrong encoding from their site.

If the website doesn't specify an encoding, changing the default to "Cyrillic (Mac OS)" should have the same effect as your AppleScript [See attached pic]


B
 

Attachments

  • Cyrillic.png
    Cyrillic.png
    111.4 KB · Views: 204
Last edited:

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
@Bal-: ooooooh

So if a site is well programmed...no matter what you do, ya still can't change its encoding controlled by default setting.?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
So if a site is well programmed...no matter what you do, ya still can't change its encoding controlled by default setting.?

Why would you do that?

If the site is correctly providing the encoding, then you telling the browser to use any other encoding is wrong.

If the site is not providing any encoding, then the default will be used. Since there is a setting for this in a Preferences pane, why wouldn't you set it there? Why would you put something you didn't want in the Preferences pane, which then forces you to choose the default you want from the Text Encoding menu?

If the site is providing the wrong encoding, then the site is wrong. The default encoding may also be wrong, but whether it's right or wrong will vary depending on the website. So you'd have to know what the website is, know that its encoding is wrong, and then manually choose the right encoding. That can't be automated because it takes a human to recognize the website is wrong, and figure out what the right encoding is.
 

greenx

macrumors newbie
Original poster
Jan 7, 2011
12
0
Why would you do that?

If the site is correctly providing the encoding, then you telling the browser to use any other encoding is wrong.

That means I don't wanna read some characters.

If the site is providing the wrong encoding, then the site is wrong. The default encoding may also be wrong, but whether it's right or wrong will vary depending on the website. So you'd have to know what the website is, know that its encoding is wrong, and then manually choose the right encoding. That can't be automated because it takes a human to recognize the website is wrong, and figure out what the right encoding is.

That's what I'm asking: if there is a way to overwrite encoding to preference default, regardless what the website programmed
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
That means I don't wanna read some characters.

That's what I'm asking: if there is a way to overwrite encoding to preference default, regardless what the website programmed

This isn't how Safari rolls. It adheres to web standards and actually wants you to read the text on websites.

As jiminaus said earlier in the thread, other browsers may behave differently. Try one. Or use other approaches to eliminate the text you object to for some reason and extract only what you want.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.