-
Notifications
You must be signed in to change notification settings - Fork 0
/
autofile.js
127 lines (105 loc) · 3.99 KB
/
autofile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*jshint es5:true*/
'use strict';
var plist = require('plist');
var fs = require('fs');
function plistFilename(app) {
return app + '/Contents/Info.plist';
}
function inspect(obj, depth) {
depth = depth || 10;
console.log(require('util').inspect(obj, {
showHidden: true,
depth: depth,
colors: true
}));
}
function findKeyHolder(obj, key) {
// console.log('testing', key);
var attempt;
if (obj instanceof Object) {
for (var k in obj) {
if (k === key) {
return obj;
} else {
attempt = findKeyHolder(obj[k], key);
if (attempt) {
return attempt;
}
}
}
}
return false;
}
module.exports = function (task) {
task
.id('tweak-macosx-app')
.name('autofile')
.author('Indigo United')
.description('Tweak an .app with custom settings. More info on the options in https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html')
.option('app', 'The .app file you want to tweak')
.option('CFBundleDisplayName', 'Bundle display name')
// .option('CFBundleTypeName', '', '')
// .option('CFBundleExecutable', 'Name of the bundle’s executable file')
.option('CFBundleName', 'The short display name of the bundle')
.option('CFBundleShortVersionString', 'The release-version-number string for the bundle')
.option('CFBundleVersion', 'The build-version-number string for the bundle')
.option('LSMinimumSystemVersion', 'LSMinimumSystemVersion', '10.6.0') // info can be found in https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html
// .option('UTTypeDescription', 'A user-readable description of this type', '') // info can be found in https://developer.apple.com/library/mac/DOCUMENTATION/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
.option('UTTypeIconFile', 'The name of the bundle icon resource to associate with this UTI.')
.option('CFBundleTypeIconFile', 'This key contains a string with the name of the icon file (.icns) to associate with this OS X document type. ')
.option('CFBundleIconFile', 'A legacy way to specify the app’s icon')
.option('UTTypeReferenceURL', 'The URL for a reference document that describes this type.')
.setup(function (opts, ctx, next) {
// group plist keys into its own object
var keys = [
'CFBundleDisplayName',
'CFBundleName',
'CFBundleShortVersionString',
'CFBundleVersion',
'LSMinimumSystemVersion',
'UTTypeIconFile',
'CFBundleTypeIconFile',
'CFBundleIconFile',
'UTTypeReferenceURL'
];
opts.keyValues = {};
keys.forEach(function (key) {
opts.keyValues[key] = opts[key];
});
next();
})
// Read the plist
.do(function (opts, ctx, next) {
opts.infoPlist = plist.parseFileSync(plistFilename(opts.app));
next();
}, {
description: 'Read {{app}} Info.plist file'
})
// Apply properties
.do(function (opts, ctx, next) {
var keyValues = opts.keyValues;
var plist = opts.infoPlist;
var propertyHolder;
// inspect(plist);
for (var k in opts.keyValues) {
propertyHolder = findKeyHolder(plist, k);
if (propertyHolder) {
console.log('found key:', k);
propertyHolder[k] = keyValues[k];
}
}
next();
}, {
description: 'Apply properties'
})
// save file
.do(function (opts, ctx, next) {
var plistStr = plist.build(opts.infoPlist).toString();
ctx.log.debugln(plistStr);
fs.writeFile(plistFilename(opts.app), plistStr, function (err) {
next(err);
});
}, {
description: 'Save Info.plist file'
});
};