GSAK (Geocaching Swiss Army Knife)
Contents - Index

MacroSet (command)

MACROSET  <Dialog=Dialog name> <VarName=Variable name> [<name=setting name>]

Dialog - This is the name of the dialog to which these settings will be updated. Valid dialog names are:

DBProperties
CacheMate
CacheMateLog
CSV
Custom
Delete
Delorme
Filter
Fugawi
GarminPOI
GcGeocaches ("Geocaching.com access=>Get geocaches")
GetMail
Grab
GPS
GPX
HTML
Load
MagellanSD
MapSend
MapSource
MapTech
MemoryMap
MoveCopy
OziExplorer
PqLoad ("Geocaching.com access=>Download pocket queries")
PocketStreets
PurgeLog
Replace
GPSReceive
S&T
StreetAtlas
TomTom
Topo
Views


VarName = This is the name of the variable that contains all the settings for this command. This variable will usually be created using the <data> command.

Name = Optional parameter and the default is <macro>. This is the setting name that will be updated/added by using the MacroSet command. As this command would usually be used to embed settings so the macro will run on any computer, you would usually use the default name of <macro>. This default name allows you to use the <macro> setting as a type of temporary work name that can be updated time and time again without affecting any other settings on the target computer. However, there may be times you do actually want to update or add a particular setting name to the relevant drop down box in the GSAK GUI (for a complete example, see this link). In this case add this parameter with the required name, but be aware if this setting does exist on the target computer it will be completely overridden without warning. 

Note: The dialog "Filter" does not have settings per se, but a saved filter name. For this dialog, to help better understand Name=, substitute "filter name" when interpreting "settings name"

MacroSet is a powerful command that enables you to embed settings and filters inside the macro language. This will let you to distribute macros to other users and not have to provide instructions on what settings are required. The end user can then run the macro without having to first create any required settings or filters. 

You can embed settings for any filter or macro command that uses the SETTINGS parameter. The VarName must be a variable that contains the contents of these settings and is usually the result of a <data> command. I really don't expect anyone to learn or follow the syntax of all the possible elements than can be in the <data> stream, but I have made generation of this data stream quite easy (I hope!)

To generate the data stream for any settings you want to embed:

1. Open the dialog you want to embed settings for
2. Set up all the items how you would like them for use in the macro
3. Click on the "save" button
4. Enter the name <macro> (very important you get this right, but it is not case sensitive)
5. Because you enter the special name of <macro>, the required code is copied to the clipboard
6. Paste the code into your required macro.

A variable name will be allocated for you, but you can change this to anything you like. Now when ever you want to use those settings for that command in a macro, you just need to use the MacroSet command with that variable, and on the command that supports settings use the name as per the name= parameter (default is <macro>)

For example: We want to distribute a macro that will first filter on all unfound caches (excluding placed by you) then copy these over to a new database called "Unfound by me". Without knowing anything about the settings or filters on the target computer you can write a macro that will do all of this for any computer that has GSAK. First, create a new macro file (either via the GSAK macro editor or your own preferred text editor). The new file will have no lines of code in it.

Open up the filter dialog, and uncheck the found box in the "found status". Also make sure you have the "Exclude caches placed by you box" ticked. Now click on the save button and enter the name <macro>. Now paste this code into your macro.

Now cancel out of the filter and go to Database=>Move/Copy Waypoints... Now change this dialog so you have the "copy" radio button selected,  the "replace" radio button selected, and the "Add" radio button selected. Now click on the "Save" button and enter the name <macro>. Now paste this code to the end of your macro. Your macro code should now look something like this:
 

<data> VarName=$Filter
edtDesc=
cbxDesc=0
cbxFilter=0
edtDistance=
cbxDistance=0
edtDistance2=
edtPlacedBy=
cbxDifficulty=0
cbxTerrain=0
cbxDif=8
cbxTer=8
cbxPlacedBy=0
cbxDif2=8
cbxTer2=8
edtUserData=
cbxUserData=0
chkReverse=False
edtTbugName=
cbxTbugName=0
chkFound=False
chkNotFound=True
chkExclude=True
chkAvailable=True
chkArchivedOnly=True
chkTempUnavailable=True
chkUserFlag1=True
chkUserFlag2=True
chkBugNo=True
cbxBugs=True
chkNoteNo=True
chkNoteYes=True
edtFull=
chkFullHighlight=True
chkRegEx=False
chkFullNotes=False
chkFullLogs=False
chkFullDes=False
RbtFullAll=True
rbtFullSelect=False
<enddata>

<data> VarName=$MoveCopy
[TfmMove]
cbxDestination.Text=test
rbtAdd.Checked=True
rbtAddFlag.Checked=False
rbtAddIgnore.Checked=False
rbtCopy.Checked=True
rbtExistIgnore.Checked=False
rbtFlagOnly.Checked=False
rbtMove.Checked=False
rbtReplace.Checked=True
rbtReplaceFlag.Checked=False
chkDisplay.Checked=True
<enddata>


Change what ever is after the cbxDestination= to Unfound by me (You couldn't do this at the time of using the move/copy dialog unless that database actually existed in your copy of GSAK)

Now to complete the macro just add the following lines to the start of the macro
 

# Save the name of the current database we are working in
$CurrentData = $_CurrentDatabase
# make sure the Unfound by me databases is empty
IF DatabaseExists("Unfound by me")
  DATABASE Name="Unfound by me" Action=delete
ENDIF
# now create a new empty database
DATABASE Name="Unfound by me" Action=create
# select the starting database again
DATABASE Name=$CurrentData
# now set up the filter <macro> and run it
MacroSet Dialog=Filter VarName=$filter
Filter Name=<macro>
# now set up the move copy settings of <macro> and do the movecopy
MacroSet Dialog=MoveCopy VarName=$MoveCopy
MoveCopy Settings=<macro>


This Macro should now run on any target computer regardless of settings and filters

Note: There are times when you may want to change the data inside your macroset variables. The easiest way to do this is by using Replace()

That is, in the <data> statement, change the items you want to be "dynamic" to a unique string. Then you can just use the Replace() function to replace the unique string to the required value. For example:
 

$BasePath="C:\Users\me\DataFiles\GeoCaching\"
$FileName = "fnmTo.Text=" + $BasePath + "Waypoints\" + $PQ_Name + ".gpx"
$GPXDynamic=Replace("UniqueString1",$filename,$GPXStatic)

MACROSET  Dialog=GPX VarName=$GPXDynamic name=<macro>
EXPORT Type=GPX Settings=<macro>

<data> VarName=$GPXStatic
[TfmExportGpx]
cbxLimit.Text=No Limit
cbxUserNotes.Checked=True
chkActual.Checked=False
chkDefault.Checked=True
chkExtra.Checked=True
chkMyLogs.Checked=False
chkSymbol.Checked=False
edtFormat.Text=%Name by %By (%Dif/%Ter)
edtMax.Text=
edtMaxGps.Text=15
edtWaypoint.Text=%code
rbtGpx.Checked=True
rbtLoc.Checked=False
edtProblem.Text=
edtExtra.Text=
chkChild.Checked=True
chkOnlyChild.Checked=False
rbtAllChildren.Checked=True
rbtOnlyFlagged.Checked=False
rbtOnlyUnFlagged.Checked=False
chkApplyName.Checked=False
chkForce.Checked=True
cbxVersion.Text=Ver 1.1
chkLogAlternate.Checked=False
UniqueString1
[TfmExportGpx.cbxRecent.Items]
Count=0
<enddata>


Note: For code clarity in this case I would probably use "GpxFileName" (without the quotes) rather than "UniqueString1". So in general, try to make the unique string something that is meaningful to the replace you are doing. Just be *sure* the string is not used anywhere else in the static data variable.
 

Alpha List         Category List
Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact