Rewriting About:Config

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Volodath
Posts: 23
Joined: Mon Jan 17, 2011 11:32 pm

Rewriting About:Config

Post by Volodath » Mon Aug 24, 2015 3:40 pm

All -

So it's been a loooooooong time since I've posted, but throughout this period I've been using iMacros on and off to accomplish various projects (great job guys).

However, recently I've run into a situation that I need some specific help for. I know there are lots of ways to solve this problem, but I'd like to have this problem solved *this way* as there are other proprietary things at work that other solutions I've explored break. It's one of those cases where I wish I could do things differently, but my hands are tied by people in positions of power that I can't persuade.

Anyway, I've long since used this neat little piece of code to rewrite the about:config file in Firefox to change where files are automatically downloaded to. It works really well for files that the plugin has a hard time catching, and in general for making things go where I want them to go regardless of something else screwing things up.

Code: Select all

var macro;
macro =  "CODE:";
macro +=  "SET !EXTRACT {{!NOW:mm-dd-yyyy-hh-nn-ss}}" + "\n"; 
iimPlay(macro)
var datecode = iimGetLastExtract(1)



//This next macro creates the variable necessary to avoid javascripting trouble in setting the default download directory
macro =  "CODE:";
macro +=  "SET !EXTRACT C:\\" + "\n"; 
iimPlay(macro)
var test = iimGetLastExtract(1)
var test = test + "\\"


//This next macro changes About:Config to end up as eventually C:\datecode
var changedirectory;
changedirectory =  "CODE:";
changedirectory +=  "URL GOTO=about:config" + "\n"; 
changedirectory +=  "WAIT SECONDS=1" + "\n"; 
changedirectory +=  "URL GOTO=javascript:var<SP>prefb<SP>=<SP>Components.classes[\"@mozilla.org/preferences-service;1\"].getService(Components.interfaces.nsIPrefBranch);var<SP>str<SP>=<SP>Components.classes[\"@mozilla.org/supports-string;1\"].createInstance(Components.interfaces.nsISupportsString);str.data<SP>=<SP>\"{{test}}{{datecode}}\";prefb.setComplexValue(\"browser.download.dir\",<SP>Components.interfaces.nsISupportsString,<SP>str);" + "\n"; 
changedirectory +=  "URL GOTO=javascript:gPrefBranch.setIntPref(\"browser.download.dir\",{{test}}{{datecode}});" + "\n"; 
iimSet("-var_test", test)
iimSet("-var_datecode", datecode)
iimPlay(changedirectory)
However, now I need to do something different - instead of just changing the default download directory, I'd like to be able to flip the about:config value of browser.download.useDownloadDir to true, as (I believe) this will force the browser to automatically download everything to the specified folder. This value is a boolean value however, not a string, and my understanding of the back-end is too slim to be able to hack this to do what I want. Are there any wizards here who can help? I'm open to other ways as long as it fits the following criteria A. double clicking a macro will change the 'Automatically download' setting to yes B. In the same macro I can write in (using the code above) where to automatically download to, C. I can reverse the value (turn it off) with another macro.

Thanks

Volo
chivracq
Posts: 9494
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Rewriting About:Config

Post by chivracq » Mon Aug 24, 2015 6:38 pm

Volodath wrote:All -

So it's been a loooooooong time since I've posted, but throughout this period I've been using iMacros on and off to accomplish various projects (great job guys).

However, recently I've run into a situation that I need some specific help for. I know there are lots of ways to solve this problem, but I'd like to have this problem solved *this way* as there are other proprietary things at work that other solutions I've explored break. It's one of those cases where I wish I could do things differently, but my hands are tied by people in positions of power that I can't persuade.

Anyway, I've long since used this neat little piece of code to rewrite the about:config file in Firefox to change where files are automatically downloaded to. It works really well for files that the plugin has a hard time catching, and in general for making things go where I want them to go regardless of something else screwing things up.

Code: Select all

var macro;
macro =  "CODE:";
macro +=  "SET !EXTRACT {{!NOW:mm-dd-yyyy-hh-nn-ss}}" + "\n"; 
iimPlay(macro)
var datecode = iimGetLastExtract(1)



//This next macro creates the variable necessary to avoid javascripting trouble in setting the default download directory
macro =  "CODE:";
macro +=  "SET !EXTRACT C:\\" + "\n"; 
iimPlay(macro)
var test = iimGetLastExtract(1)
var test = test + "\\"


//This next macro changes About:Config to end up as eventually C:\datecode
var changedirectory;
changedirectory =  "CODE:";
changedirectory +=  "URL GOTO=about:config" + "\n"; 
changedirectory +=  "WAIT SECONDS=1" + "\n"; 
changedirectory +=  "URL GOTO=javascript:var<SP>prefb<SP>=<SP>Components.classes[\"@mozilla.org/preferences-service;1\"].getService(Components.interfaces.nsIPrefBranch);var<SP>str<SP>=<SP>Components.classes[\"@mozilla.org/supports-string;1\"].createInstance(Components.interfaces.nsISupportsString);str.data<SP>=<SP>\"{{test}}{{datecode}}\";prefb.setComplexValue(\"browser.download.dir\",<SP>Components.interfaces.nsISupportsString,<SP>str);" + "\n"; 
changedirectory +=  "URL GOTO=javascript:gPrefBranch.setIntPref(\"browser.download.dir\",{{test}}{{datecode}});" + "\n"; 
iimSet("-var_test", test)
iimSet("-var_datecode", datecode)
iimPlay(changedirectory)
However, now I need to do something different - instead of just changing the default download directory, I'd like to be able to flip the about:config value of browser.download.useDownloadDir to true, as (I believe) this will force the browser to automatically download everything to the specified folder. This value is a boolean value however, not a string, and my understanding of the back-end is too slim to be able to hack this to do what I want. Are there any wizards here who can help? I'm open to other ways as long as it fits the following criteria:
-A. double clicking a macro will change the 'Automatically download' setting to yes.
-B. In the same macro I can write in (using the code above) where to automatically download to.
-C. I can reverse the value (turn it off) with another macro.

Thanks

Volo
CIM...! :mrgreen: (... For me to read your Question... (And the 'C' stands for... 'CONFIG'..., oops...!))
Last edited by chivracq on Mon Aug 24, 2015 11:50 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Volodath
Posts: 23
Joined: Mon Jan 17, 2011 11:32 pm

Re: Rewriting About:Config

Post by Volodath » Mon Aug 24, 2015 7:22 pm

chivracq wrote: CIM...! :mrgreen: (... For me to read your Question... (And the 'C' stands for... 'CONFIG'..., oops...!))

Sorry. Firefox 39.0, plugin build 8920312, Win 7 Ultimate.
chivracq
Posts: 9494
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Rewriting About:Config

Post by chivracq » Tue Aug 25, 2015 12:26 am

Volodath wrote:
chivracq wrote: CIM...! :mrgreen: (... For me to read your Question... (And the 'C' stands for... 'CONFIG'..., oops...!))
Sorry. Firefox 39.0, plugin build 8920312, Win 7 Ultimate.
Good-good-good...! :D

Interesting Question, and pity you don't check the Forum a bit more often, I think you are indirectly giving the/a Solution to another Thread from about 1 year ago (the Syntax you are using was supposed not to work anymore since a specific FF Version, FF14 maybe...), I'll need to locate that Thread..., the User ended up choosing to use a dedicated FF Profile with some specific 'about:config' Settings, that might be a way to go for you as well if we don't find a way to write to a Boolean...

Although interesting because of the Syntax you are using, there is already a Mechanism in iMacros where you can specify the Download Directory as some Parameter for 'ONDOWNLOAD', but...!, it's buggy and broken for iMacros for FF v8.9.x for PDF and XLS Downloads (there are 3-4-5 Threads related to that Pb...) (you don't mention for what kind of File Formats you use 'ONDOWNLOAD'...), I think it works for other File Formats, and I think it works as well for v8.8.2 (for all Files) which is the Version I still use (together with Pale Moon v24.6.2 instead of plain FF...), the Problem has been known for quite a while by TechSupport (and Dev I reckon/hope...), v8.9.3 (Beta) was released 3 days ago (available from the Version History Page), it might correct it, even if not mentioned...

Elaborate otherwise why you use your 'gPrefBranch()' Syntax instead of the 'FOLDER' Parameter with 'ONDOWNLOAD'..., and I'll have a look at your Syntax and if I can find a way to write to a Boolean in 'about:config'...

(Some way to investigate is how iMacros is able to toggle Images ON/OFF with the 'FILTER' Command, I guess it's toggling a YES/NO Boolean in the 'about:config' as well... :idea: )

(And I think I will check your older Threads, might be some interesting Reading...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Volodath
Posts: 23
Joined: Mon Jan 17, 2011 11:32 pm

Re: Rewriting About:Config

Post by Volodath » Tue Aug 25, 2015 4:05 am

chivracq wrote:
Volodath wrote:
chivracq wrote: CIM...! :mrgreen: (... For me to read your Question... (And the 'C' stands for... 'CONFIG'..., oops...!))
Sorry. Firefox 39.0, plugin build 8920312, Win 7 Ultimate.
Good-good-good...! :D

Interesting Question, and pity you don't check the Forum a bit more often, I think you are indirectly giving the/a Solution to another Thread from about 1 year ago (the Syntax you are using was supposed not to work anymore since a specific FF Version, FF14 maybe...), I'll need to locate that Thread..., the User ended up choosing to use a dedicated FF Profile with some specific 'about:config' Settings, that might be a way to go for you as well if we don't find a way to write to a Boolean...

Although interesting because of the Syntax you are using, there is already a Mechanism in iMacros where you can specify the Download Directory as some Parameter for 'ONDOWNLOAD', but...!, it's buggy and broken for iMacros for FF v8.9.x for PDF and XLS Downloads (there are 3-4-5 Threads related to that Pb...) (you don't mention for what kind of File Formats you use 'ONDOWNLOAD'...), I think it works for other File Formats, and I think it works as well for v8.8.2 (for all Files) which is the Version I still use (together with Pale Moon v24.6.2 instead of plain FF...), the Problem has been known for quite a while by TechSupport (and Dev I reckon/hope...), v8.9.3 (Beta) was released 3 days ago (available from the Version History Page), it might correct it, even if not mentioned...

Elaborate otherwise why you use your 'gPrefBranch()' Syntax instead of the 'FOLDER' Parameter with 'ONDOWNLOAD'..., and I'll have a look at your Syntax and if I can find a way to write to a Boolean in 'about:config'...

(Some way to investigate is how iMacros is able to toggle Images ON/OFF with the 'FILTER' Command, I guess it's toggling a YES/NO Boolean in the 'about:config' as well... :idea: )

(And I think I will check your older Threads, might be some interesting Reading...)
So actually I mistake, the version I'm running that that code works on is FF 3.6.16, Plugin 7300701.

Anyway, I'm running that version specifically because it lets me do this. I'm also running that version and have to tackle the problem this way because of internal office politics. I'm not allowed to interact with the web server in any type of programmatic access, despite the fact that I need to update a few different key metrics (and export the data for those metrics) fairly frequently. This leads to me wanting to flip the 'automatic download' and 'automatic download location' rather quickly as opposed to editing those values by hand.

I suppose a profile switcher would provide the same benefit, as long as it's something I can tie to the menu/toolbar. Thanks for the tip, and good luck with this little nugget. As for why I used gPrefBranhc()... it's all I could find at the time. This is something like four years ago, things have changed a lot since then. I hardly knew programming at the time (I think my first questions were about string manipulation), and now I know enough to know I don't know enough but I know that I need to get things working. The code work(ed), I'm just looking to expand on it a little bit. Now to find a profile switcher...
chivracq
Posts: 9494
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Rewriting About:Config

Post by chivracq » Tue Aug 25, 2015 4:43 pm

Volodath wrote:So actually I mistake, the version I'm running that that code works on is FF 3.6.16, Plugin 7300701.

Anyway, I'm running that version specifically because it lets me do this. I'm also running that version and have to tackle the problem this way because of internal office politics. I'm not allowed to interact with the web server in any type of programmatic access, despite the fact that I need to update a few different key metrics (and export the data for those metrics) fairly frequently. This leads to me wanting to flip the 'automatic download' and 'automatic download location' rather quickly as opposed to editing those values by hand.

I suppose a profile switcher would provide the same benefit, as long as it's something I can tie to the menu/toolbar. Thanks for the tip, and good luck with this little nugget. As for why I used gPrefBranhc()... it's all I could find at the time. This is something like four years ago, things have changed a lot since then. I hardly knew programming at the time (I think my first questions were about string manipulation), and now I know enough to know I don't know enough but I know that I need to get things working. The code work(ed), I'm just looking to expand on it a little bit. Now to find a profile switcher...
Hum, so I was correct about the old Syntax and it stopped working indeed from FF14.
I'm a bit surprised btw that your IT Department lets you use such an old Version of FF, FF3 must be full of Security Vulnerabilities, I would think...

What I stated about 'ONDOWNLOAD' and 'FOLDER' (still) working in v8.8.2 was incorrect, I remember doing some Testing with that Version in some other Thread (- Saving PDF works manually, but not with iMacros, interesting Thread for you to read btw and it is related to your Pb..., and that could be a good occasion to bump it...!) for the Automatic Download and it was already broken in that Version...

Here you have another Thread related to writing to 'about: config' and trying to use the same Syntax like yours, where a User came with some other Workaround (using a C# Windows Application to handle the 'about: config' part):
- [Edited]How can I change socks 5 in imacros firefox 27.0.1 ?

Using Dedicated Profiles like I already mentioned is an option, I use 3 different FF Profiles (well, Pale Moon instead of FF) with 3 different Shortcuts on my Desktop and within each Profile, I have a Shortcut to the other 2 ones that I can launch with 1 Click from within PM using the FF Add-on 'External Application Buttons' with eventually a Keyboard Shortcut that even allows me to launch them from within a Macro using the EVENT Mode...

But I guess your ultimate goal is to be able to download your Files to a few specific Locations. As the 'ONDOWNLOAD' + 'FOLDER' Mechanism is broken at this moment and you can only download Files automatically to the FF Default Directory, you could do so and have a few .BAT Files that will move the Files downloaded to your specific Locations, and you can still use 'External Application Buttons' with those .BAT Files to launch them with 1 Click after you've run your Macro or you can even call the specific .BAT File directly at the end of your Macro using the EVENT Mode.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Volodath
Posts: 23
Joined: Mon Jan 17, 2011 11:32 pm

Re: Rewriting About:Config

Post by Volodath » Tue Aug 25, 2015 5:24 pm

chivracq wrote: But I guess your ultimate goal is to be able to download your Files to a few specific Locations. As the 'ONDOWNLOAD' + 'FOLDER' Mechanism is broken at this moment and you can only download Files automatically to the FF Default Directory, you could do so and have a few .BAT Files that will move the Files downloaded to your specific Locations, and you can still use 'External Application Buttons' with those .BAT Files to launch them with 1 Click after you've run your Macro or you can even call the specific .BAT File directly at the end of your Macro using the EVENT Mode.
Specifically, it's to be able to set the download folder and the ability to automatically save downloads (bypass the dialog box) without having to do much work. I already have a process to handle them once they're downloaded (folderspy + scripts), but since a couple of the files are named the same but need to do different things, always saving them to the same place runs into some headaches (and I don't feel like writing something to identify what type of file with the same name it is, as there's a lot of cross over).

Could you elaborate more on triggering batch files with External Application Buttons and .BAT files? Could I write a batch file to switch profiles while FF is still open, which would let me change download behavior/folder with a single click?

I don't mind using 3.6.16 as I only use it for the one site. Maybe while traveling I'll attempt again to write the boolean value. It shouldn't be that hard.
theabdulrab
Posts: 4
Joined: Sun Jul 05, 2015 10:45 pm

Re: Rewriting About:Config

Post by theabdulrab » Fri Sep 02, 2016 8:25 pm

Hi,

To toggle JS ON or OFF you can use the following code:

var pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
pref.setBoolPref("javascript.enabled", 1);

If you want to set integer values:

var pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
pref.setIntPref("extensions.imacros.af-runtime-value", 190);


Thank you.
chivracq
Posts: 9494
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Rewriting About:Config

Post by chivracq » Sat Sep 03, 2016 4:04 am

theabdulrab wrote:Hi,

To toggle JS ON or OFF you can use the following code:

Code: Select all

var pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
pref.setBoolPref("javascript.enabled", 1);
If you want to set integer values:

Code: Select all

var pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
pref.setIntPref("extensions.imacros.af-runtime-value", 190);
Thank you.
Hum, first time Poster in the Thread... => Sorry, "CIM" for you as well for me to read your Qt, (I've already asked you in some previous Thread(s) of yours...), and if you are posting an Answer/Solution to the current Thread, you should mention in which FCI you've tested it...
(iMacros for FF v9.0.3, latest recent Version for FF, is breaking many-many things...)

EDIT: Hum, read your Post ah-ah...!, => posting a Solution and not a Qt, Thanks then already, sorry for being so harsh but I don't read when People don't mention their FCI, and you are not a "known" Thread-Answerer, so I took for granted that you were asking a Qt (hopefully related to the original OP...), but hum, you should still mention your FCI..., iMacros for FF v9.0.3 is really breaking many things that were working in v8.9.x...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply