steam-shortcut-editor
v3.1.3
Published
Edit Steam shortcuts
Downloads
3,475
Readme
steam-shortcut-editor
npm i steam-shortcut-editor
Edit Steam Shortcuts using Node.js
Read/Write Steam shortcuts.vdf
file.
This file is found in $SteamDirectory/userdata/$SteamUserId/config
.
After modifying the file, Steam will need to be restarted. If you modify the file, then add a Non-Steam Game using the Steam UI, it will overwrite the file. If the file is not formatted correctly after Steam restarts, it will delete the file. Be sure to backup the file before messing with it.
This has been tested on Windows and various distributions of linux.
Sample Program
To run the sample.js
file, the environment variable STEAM_USER_ID
should be defined to the Steam id used in the file path to the shortcuts.vdf
file. The sample.js
will read in shortcuts.vdf
, dump the JSON representation to the console, then rewrite the file into shortcuts_write.vdf
file.
If not on Windows (or your Steam directory isn't C:/Program Files (x86)/Steam
) you can set the Steam directory by setting the environment variable STEAM_DIRECTORY
.
Data Contract - Shortcut Object
To add new shortcuts, write an object that looks like:
{
"shortcuts": [
{
"AppName": "Minecraft - FTB",
"exe": "\"C:\\Path\\With Space\\To\\some.exe\"",
"StartDir": "\"C:\\Path\\With Space\\To\\\"",
"IsHidden": false,
"icon": '',
"AllowDesktopConfig": true,
"OpenVR": false,
"tags": [
"favorite"
]
},
//.. more shortcut objects
]
}
AppName
: Name shown in Steam. (the casing seems to vary, have seen it appear asappname
)exe
: Path to exe file to run. Should be within quotes.StartDir
: Path to directory to run the exe file within. Should be within quotes. Typically, should be directory containing exe file.icon
: Path to icon file. If left blank, will use the icon for the exe file.IsHidden
: Should be boolean value.LastPlayTime
: Date of last play. To automatically parse this value, includedateProperties: ['LastPlayTime']
in the parser options.tags
: Array of tags. If no tags are desired, it should be an empty array.
Usage
npm i steam-shortcut-editor --save
var shortcut = require('steam-shortcut-editor');
var filePath = 'full/path/to/shortcuts.vdf';
var writePath = filePath.replace('shortcuts','shortcuts_write');
shortcut.parseFile(filePath,
{ autoConvertArrays: true, autoConvertBooleans: true, dateProperties: ['LastPlayTime']},
function(err, obj, inputBuffer){
if(err){
console.log('failed to read '+filePath);
return;
}
//Buffer read from file
console.log('Raw Buffer:', inputBuffer);
//Parsed Object
console.log(JSON.stringify(obj,null,2));
shortcut.writeFile(writePath, obj, function (err) {
if(err){
console.log('failed to write '+writePath);
}
});
});
Parsing
There are two parsing functions exposed:
shortcut.parseFile(filePath[, options], callback)
: Usesfs
to read file asBuffer
, then usesshortcut.parseBuffer
to parse it.- The callback should be
function (err, parsedObject, inputBuffer) { ... }
- The callback should be
shortcut.parseBuffer(buffer[, options])
The parse functions accept an optional options
argument. This options
argument should be an object the looks like:
{
autoConvertBooleans: true,
autoConvertArrays: true,
dateProperties: ['LastPlayTime']
}
- If
autoConvertBooleans
is truthy, numbers that equal1
will be set totrue
and numbers that equal0
will be set tofalse
. Handles the common flags within a shortcut object. - If
autoConvertArrays
is truthy, any objects with only numbers for properties (like theshortcuts
object) will be changed to be arrays. - The
dateProperties
array is used to indicate properties that should be automatically adjusted from numbers toDate
objects. Numbers are adjusted to dates by doingnew Date(number * 1000)
.
If no options are provided, it will use the default settings of { autoConvertBooleans: true, autoConvertArrays: true }
.
This library does not make any property name/value assumptions. It is up to you to handle the weird variations in property names. It is also up to you to explicitly include any date properties you need parsed in the dateProperties
parse option.
Writing
There are two writing functions exposed:
shortcut.writeFile(filePath, obj, callback)
: Writes the object to the file after converting to aBuffer
usingshortcut.writeBuffer
.- The callback should be
function (err) { ... }
- The callback should be
shortcut.writeBuffer(obj)
: returns aBuffer
that can be written to a file
The writing functions will automatically convert..
- boolean values to the numbers
1
and0
(fortrue
andfalse
) Date
objects to numbers (usingdate.valueOf() / 1000
)- arrays to objects
null
andundefined
to empty string