Cookie toggler

Can anyone think up an applescript which will toggle between “Accept cookies” and “refuse cookies” ?

Of course I can obtain the same result by going to the Edit menu > Preferences > Advanced > but it would be so much simpler to let an applescript do it (after assigning it to a key)

Thanks for a try.

maurice
(Beige G3 Desktop, OS 9.2)

Hmmm…since there have been no replies to this I’ll throw in my “outside the box” thinking on the matter.

How about setting your browser to accept cookies and then making a copy of it’s preferences file into a separate folder…say “cookies on folder” then turn them off and make a copy of it’s preferences into a “cookies off folder”

Then all you would have to do is have applescript replace the preferences file that’s in the proper location with one of the backup files and it would switch the settings.

Of course you would have to update the swap files whenever you made a change to your preferences but how often do you really do that?

Another option is to use an old program like “rescompare” to compare the cookies on preferences file to the cookies off file and vice versa then you could create a resource patch which only changes the part of the prefs file responsible for cookies and have applescript run the patch for you.

Unfortunately I don’t see anything in IE’s dictionary for setting prefs so I don’t forsee an easy way of doing this.

Thank you, Eaglesong3, for giving it a try. In fact I use Netscape Communicator 4.77 and I found out that its dictionary didn’t contain anything that could be used to toggle the cookie file. So I tried an approach similar to yours with the following script (done by Recording with the Script Editor):

tell application “Finder”
activate
select file “MagicCookie” of folder “Maurice” of folder “Netscape Users” of folder “Preferences” of folder “System Folder” of startup disk
set locked of file “MagicCookie” of folder “Maurice” of folder “Netscape Users” of folder “Preferences” of folder “System Folder” of startup disk to false
open file “cookies clipping”
end tell

Note that he above script opens on the desktop a small clipping which reminds me that cookies are now accepted.
I also made a separate script, identical to the first, but with “true” instead of “false” and “close” instead of “open”
It works very well, so I assigned (using EasyKeys) the 2 scripts to the keypad as follows: + for Allow and - for Refuse.

Very handy, except that now I can’t use the + and - keypad keys for anything else. Oh well…

As you can see, I am not proficient with applescript, which I find fairly opaque. I have not yet found a script that will write today’s short date (21/04/05) Please let me know if you can solve that one.

I’m fairly “new” at applescript myself. I’ve been plugging at it for a while but never seriously. It’s only been recently (since I lost my Cable TV and internet and have nothing better to do) that I’ve been really playing with it.

I just recently wrote out a script to present the date as you want it. Unfortunately, I could not find an easy way for it to return the month.

The command to retrieve date parts is:

Get “date part” of (current date)

I’ve found that “current date” needs to be in parenthesis or it thinks it’s a function.

When you do

get month of (current date) however it returns “April”, etc.

I just did a series of If statements to handle that


set myday to day of (current date) as text
set myyear to year of (current date) as text
set mymonth to month of (current date) as text
if mymonth is equal to "January" then set mymonth to 1
if mymonth is equal to "February" then set mymonth to 2
if mymonth is equal to "March" then set mymonth to 3
if mymonth is equal to "April" then set mymonth to 4
if mymonth is equal to "May" then set mymonth to 5
if mymonth is equal to "June" then set mymonth to 6
if mymonth is equal to "July" then set mymonth to 7
if mymonth is equal to "August" then set mymonth to 8
if mymonth is equal to "September" then set mymonth to 9
if mymonth is equal to "October" then set mymonth to 10
if mymonth is equal to "November" then set mymonth to 11
if mymonth is equal to "December" then set mymonth to 12
display dialog (myday & "/" & mymonth & "/" & myyear)

If you don’t tell it to set your variables “as text” then it tells you “can’t make the data into a string” or something like that.

If you want just the “05” from the year then tell it to:


set myday to day of (current date) as text
set myyear to year of (current date) as text
set shortyear to (character 3 of myyear & character 4 of myyear)
set mymonth to month of (current date) as text
if mymonth is equal to "January" then set mymonth to 1
if mymonth is equal to "February" then set mymonth to 2
if mymonth is equal to "March" then set mymonth to 3
if mymonth is equal to "April" then set mymonth to 4
if mymonth is equal to "May" then set mymonth to 5
if mymonth is equal to "June" then set mymonth to 6
if mymonth is equal to "July" then set mymonth to 7
if mymonth is equal to "August" then set mymonth to 8
if mymonth is equal to "September" then set mymonth to 9
if mymonth is equal to "October" then set mymonth to 10
if mymonth is equal to "November" then set mymonth to 11
if mymonth is equal to "December" then set mymonth to 12
display dialog (myday & "/" & mymonth & "/" & shortyear)

Eaglesong3,

You are doing very well indeed. No one else came up with the right answer to my query.
The only changes I did was to modify the month number by putting a zero in front and encasing the result in parenthesis. thus 4 became (04)
Also, as I needed this script to write the date on the active document, I replaced “Display dialog” with:
tell application “Tex-Edit Plus”
if not (front window exists) then
beep
else
copy (myday & “/” & mymonth & “/” & shortyear) as string to selection
end if
end tell

It works well but only with T-E+. (It would be better still if it could be made to write on other supports, for example, Stickies or a filename in the Finder.)
While you are off TV, perhaps you could advise me on how to assign a script (saved as an App. and clicking on “never show startup screen”) to a key combination (all my FKeys are busy)
Tex-Edit Plus manual says to add to the script nameD+S (if the chosen keys will be Command Shift D.)
It works but it only opens the startup screen or the script and I have to press on Run to run the script. This is strange since I enabled “never show startup screen”, and considering that double clicking on the script icon does run it at once. What is need here is a second script that will trigger the first one, but that would only only move the problem sideways. Any clue?
Maurice

Perhaps a program such as EasyKeys (that one might be windows only) or FunKeys. Basically any hotkey program. I’m not sure why it shows the startup screen on an applescript app which says not to though…

As a side note for writing the date…I can’t remember the name of it but there is a scripting addition you can find on the net that allows a “type text” command. That command will allow you to actually type text to any active application as if you had punched the keys yourself so no copying and pasting required. I use it for a stat program I wrote as well as to enter some of my more commonly used passwords into applications.

It only allows you to type 20 characters at a time but that’s not really a problem since you can string as many “type text” commands together as you need to.

Do you mean “AutoText Typer”? Yes it’s very handy, but it will only enter the date as YY/MM/DD. I use it for that too.
I have both EasyKeys and FunKeys. They work well, but FunKeys only assigns to Function keys (and mine are all used up)

The scripting addition is called “Sigma’s Additions”

All it does it type what you tell it to into an application. So you can do something like


set firstvar to "I "
set secondvar to "love "
set thirdvar to "applesript"

Tell Application "SimpleText"
     Activate
          type text (firstvar & secondvar & thirdvar)
end tell

It will go to SimpleText and type in “I love applescript” as if you had typed it out on the keyboard.

So when you use the script for creating the date in the format you wanted then all you have to do is tell your application to “type text (myday & “/” & mymonth & “/” & shortyear)” and it will type it to the application.