function run() { var studio_map = { "tt-ideas-ltd":"", "baby-care-games":"", "baby-care-inc":"", "beauty-salon-games":"", "big-bear-entertainment-inc":"", "buffy-moon-ltd":"", "dress-up-media":"", "fast-builder-limited":"", "food-maker-inc":"", "fun-factory":"", "girl-games-maker":"", "jam-jello":"", "kids-food-games-inc":"", "kids-games-media":"", "kids-go-games":"", "mini-pet-media-inc":"", "mommy-me":"", "pink-toys":"", "pixel-girl-labs":"", "princess-dreams-media-inc":"", "sniper-studio":"", "tick-tock-apps":"", "time-out-apps-inc":"", "turbo-fire":"", "surprise-labs-ltd":"", "gummy-apps-company-ltd":"", "oozy-slime":"", "pop-it-media-co-ltd":"", "green-monster":"", "white-cat-games":"", "blue-eyes":"", "pink-slime":"", "very-pink-company-ltd":"", "smashing-apps":"", "meta-apps-inc":"", "double-fun-ltd":"", "double-purple":"", "no-hair-ltd":"", "shake-it":"", "simply-fun-media":"", "maker-labs":"", "crazy-kids-media":"", "pocket-princess":"", "salon":"", "girl-games":"", "hugs-n-hearts":"", } var app = Application.currentApplication(); app.includeStandardAdditions = true; function get_split_comma(key) { if (!key.includes(":")) { return ":"; } if (!key.includes("#")) { return "#"; } if (!key.includes("@")) { return "@"; } } function inputInfo() { var studio = {}; while (!Object.keys(studio_map).includes(studio.textReturned)) { studio = app.displayDialog( "Studio name(lower case, replace space with -, and remove all special characters)", { defaultAnswer: "tt-ideas-ltd", withIcon: "note", buttons: ["Continue"], defaultButton: "Continue", } ); } var email = app.displayDialog("dev Email", { defaultAnswer: "dev@tt-ideas.com", withIcon: "note", buttons: ["Continue"], defaultButton: "Continue", }); var password = app.displayDialog("dev Password", { defaultAnswer: "password", withIcon: "note", buttons: ["Continue"], defaultButton: "Continue", }); return { studio: studio.textReturned, email: email.textReturned, password: password.textReturned, }; } function confirmInfo(studio, email, password) { var confirm = app.displayDialog( "Please confirm the following information \n Studio: " + studio + "\n Email: " + email + "\n Password: " + password, { withIcon: "note", buttons: ["Continue", "Cancel"], defaultButton: "Continue", } ); return confirm.buttonReturned == "Continue"; } function updateConfig(a,b){ split_comma = get_split_comma(b); app.doShellScript( ' sed -i "" "s' + split_comma + a + split_comma + b + split_comma + 'g" ' + filePath + "config.json" ); } var info = inputInfo(); while (!confirmInfo(info.studio, info.email, info.password)) { info = inputInfo(); } var studio = info.studio; var email = info.email; var password = info.password; var filePath = "~/AppleConnectAgent/"; var home = app.doShellScript("cd ~ && pwd") + "/"; app.doShellScript(" rm -rf " + filePath); app.doShellScript( " git clone http://xuzepei:99565a73a3e7e4028229d794ca4eb92c1a6206a3@47.99.80.178:8081/shenlinwei/AppleConnectAgent.git " + filePath ); app.doShellScript( " cp " + filePath + "config.json.example " + filePath + "config.json" ); app.doShellScript( " cp " + filePath + "start.sh.example " + filePath + "start.sh" ); app.doShellScript( " cp " + filePath + "com.nexa.apple.connect.agent.plist.example " + home + "/Library/LaunchAgents/com.nexa.apple.connect.agent.plist" ); var split_comma = get_split_comma(studio); updateConfig("{STUDIO}", studio) updateConfig("{ACCOUNT}",email) updateConfig("{PASSWORD}",password) updateConfig("{AGENT_PATH}",filePath) app.doShellScript( 'sed -i "" "s' + split_comma + "{AGENT_PATH}" + split_comma + home + "AppleConnectAgent" + split_comma + 'g" ' + home + "Library/LaunchAgents/com.nexa.apple.connect.agent.plist" ); app.doShellScript( 'sed -i "" "s' + split_comma + "{AGENT_PATH}" + split_comma + home + "AppleConnectAgent" + split_comma + 'g" ' + filePath + "start.sh" ); app.doShellScript( " launchctl unload " + home + "Library/LaunchAgents/com.nexa.apple.connect.agent.plist" ); app.doShellScript( " launchctl load -w " + home + "Library/LaunchAgents/com.nexa.apple.connect.agent.plist" ); console.log("done"); }