Skip to content

Instantly share code, notes, and snippets.

@suparngp
Last active June 1, 2016 15:50
Show Gist options
  • Save suparngp/5bf8891c0476ec5d51d9 to your computer and use it in GitHub Desktop.
Save suparngp/5bf8891c0476ec5d51d9 to your computer and use it in GitHub Desktop.
Turn websites into Mac Applications with all the chrome extensions like Adblock, Ghostery. Any time you install an extension in your main chrome instance, those extensions are also available within your web apps. Copy the two files under /usr/local/bin and make them executable by running chmod +x /usr/local/bin/chromer chmod +x /usr/local/bin/ch…
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var appName = "";
var appURL = "";
var appIcon = "";
var chromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
var appRoot = "/Applications/Web Apps"
var extensionsLocation = "/Library/Application Support/Google/Chrome/Default/Extensions/"
var homeDir = process.env.HOME || process.env.USERPROFILE;
var extensionsDir = path.join(homeDir, extensionsLocation);
var extensions = fs.readdirSync(extensionsDir);
var exts = [];
var versions = [];
var ignoredExtensions = ["Google Slides",
"Google Docs",
"Google Drive",
"YouTube",
"Google Search",
"Google Sheets",
"Google Docs Offline",
"Chrome Web Store Payments",
"Gmail"
];
function ignore(filePath) {
if (["Temp", ".DS_Store"].indexOf(filePath) !== -1) {
return true;
}
return false;
}
for (var ext in extensions) {
if (ignore(extensions[ext])) {
continue;
}
exts.push(path.join(extensionsDir, extensions[ext]));
}
for (var ext in exts) {
var v = fs.readdirSync(exts[ext]);
for (var i in v) {
if (ignore(v[i])) {
continue;
}
versions.push(path.join(exts[ext], v[i]));
}
}
var j = [];
var furtherCheck = [];
versions = versions
.filter(function(version) {
var manifestPath = path.join(version, "manifest.json");
try {
var manifestPath = path.join(version, "manifest.json");
fs.accessSync(manifestPath, fs.R_OK);
var json = require(manifestPath);
if (json["name"].indexOf("__") !== 0) {
return true;
}
var messageName = json["name"].replace(/(MSG)|_/gi, "");
if (messageName === "APPNAME") {
messageName = "app_name";
}
furtherCheck.push({
messageName: messageName,
version: version
});
return false;
} catch (error) {
return false;
}
});
var enLocales = ["en", "en_US"];
versions = versions.concat(
furtherCheck.filter(function(obj) {
var extension = obj.version;
var localePath = path.join(extension, "_locales");
try {
var locales = fs.readdirSync(localePath);
var en = locales.filter(function(locale) {
return enLocales.indexOf(locale) !== -1;
}).map(function(locale) {
return path.join(localePath, locale);
})[0];
if (en) {
var messages = require(path.join(en, "messages.json"));
if (!messages[obj.messageName]) {
return false;
}
return ignoredExtensions.indexOf(messages[obj.messageName].message) === -1;
}
} catch (error) {
}
})
.map(function(obj){
return obj.version;
}));
var finalVersions = versions.map(function(e) {
return e;
}).join(",");
console.log(finalVersions);
#!/bin/sh
echo "What is the name of the app (Spaces allowed e.g. Google Mail)?"
read inputline
name="$inputline"
echo "What is the url (e.g. https://www.google.com)?"
read inputline
url="$inputline"
echo "What is the full path (expand home directory) to the icon (e.g. /Downloads/icon.png)?"
read inputline
icon="$inputline"
chromePath="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
appRoot="/Applications/Web Apps"
homeDir=~
mkdir -p "$appRoot"
# various paths used when creating the app
resourcePath="$appRoot/$name.app/Contents/Resources"
execPath="$appRoot/$name.app/Contents/MacOS"
randDir=$(jot -r 1 10000000000 99999999999)
profilePath="$homeDir/Library/Application Support/$name/$randDir"
plistPath="$appRoot/$name.app/Contents/Info.plist"
# make the directories
mkdir -p "$resourcePath" "$execPath"
# convert the icon and copy into Resources
if [ -f "$icon" ] ; then
sips -s format tiff "$icon" --out "$resourcePath/icon.tiff" --resampleHeightWidth 128 128 >& /dev/null
tiff2icns -noLarge "$resourcePath/icon.tiff" >& /dev/null
fi
# create the executable
cat > "$execPath/$name" <<EOF
#!/bin/bash
export PATH="$PATH"
echo "\$PATH"
if [ ! -d "$profilePath" ]; then
echo "I am creating profile $profilePath"
mkdir -p "$profilePath"
touch "$profilePath/First Run"
fi
EOF
echo 'extensions=$(chrome-extensions)' >> "$execPath/$name"
echo 'echo Extensions $extensions' >> "$execPath/$name"
echo 'syslog -s "\$extensions"' >> "$execPath/$name"
cat >> "$execPath/$name" <<EOF
echo "\$extensions"
exec "$chromePath" --disable-save-password-bubble --app="$url" --no-first-run --load-extension="\$extensions" --user-data-dir="$profilePath" "\$@"
EOF
# cat >"$execPath/$name" <<EOF
# #!/bin/sh
# if [ ! -d "$profilePath" ]; then
# echo "I am creating profile $profilePath"
# mkdir -p "$profilePath"
# touch "$profilePath/First Run"
# fi
# echo "Evaluating"
# extensions=$(chrome-extensions)
# echo "Extensions $extensions"
# exec "$chromePath" --disable-save-password-bubble --app="$url" --no-first-run --load-extension="$extensions" --user-data-dir="$profilePath" "\$@"
# EOF
chmod +x "$execPath/$name"
# create the Info.plist
cat > "$plistPath" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>CFBundleName</key>
<string>$name</string>
<key>CFBundleExecutable</key>
<string>$name</string>
<key>CFBundleIconFile</key>
<string>icon</string>
<key>CFBundleIdentifier</key>
<string>com.suparn.$name</string>
</dict>
</plist>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment