AutoControl Control your browser your way Forum               Install now from theChrome Web Store

ACtl.pubVar


This function is identical to ACtl.var (same arguments and behavior), except that it works with public variables instead of private ones.
Public variables created by one script can be read and modified by any other AutoControl script.
Additionally, variables created with this function can be used as Placeholders in some GUI actions such as open url, bookmark tabs, clipbrd put, and others. See example below.

Examples

From Script 1.

	//Set private `variable1`
	await ACtl.var('variable1', 'Script 1 private') ;
	//Set public `variable1`
	await ACtl.pubVar('variable1', 'Script 1 public') ;
	

From Script 2.

	//Set private `variable1`
	await ACtl.var('variable1', 'Script 2 private') ;
	
	//Get private and public `variable1`
	let privateVar1 = await ACtl.var('variable1') ;
	let publicVar1 = await ACtl.pubVar('variable1') ;
	
	console.log('Private var1', privateVar1) ; //outputs 'Script 2 private'
	console.log('Public var1', publicVar1) ; //outputs 'Script 1 public'
	

Passing a value from a script to a GUI action.
Suppose we want to grab the URL of the link the mouse is pointing at, and then pass that URL to the open url action.
First, we run this script to get the URL under the mouse and save it to a public variable.

	//Get the link element under the mouse (if any)
	let link = document.querySelector('[href]:hover') || {} ;
	//Save the link's 'href' property to a public variable
	await ACtl.pubVar('urlUnderMouse', link.href) ;
	

Then, that variable can be used in the open url action by means of the <var.urlUnderMouse> placeholder.
Scripting API Script Isolation Asynchronicity Backgrnd Scripts GUI vs API ACtl.include ACtl.import ACtl.getFile ACtl.saveFile ACtl.saveURL ACtl.openURL ACtl.closeTab ACtl.runInTab ACtl.runInFrames ACtl.runInPageCtx ACtl.getTabInfo ACtl.getTabIds ACtl.TAB_ID ACtl.setTabState ACtl.captureTab ACtl.execAction ACtl.runCommand ACtl.getClipboard ACtl.setClipboard ACtl.expand ACtl.switchState ACtl.var ACtl.pubVar ACtl.on ACtl.off ACtl.sleep ACtl.STOP_CHAIN ACtl.STOP_FULL_SEQ