Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple test to warn if SwiftRuntimeForCommandLineTools.dmg is needed (like 10.14.3 or older). (feature request) #49

Open
porteusconf opened this issue Jan 16, 2023 · 0 comments

Comments

@porteusconf
Copy link

Maybe add warning inside app for those (like me) that did not read the Readme.md saying that SwiftRuntimeForCommandLineTools.dmg may be needed for macos 10.14.3 and earlier. (This app should run on macos 10.11, 10.12, and 10.13 high sierra, tho I think the Swift-runtime typically may only be needed for 10.12 or 10.13) In any case, I think we can check if Swift-runtime is needed by seeing if this file exists:

/usr/lib/swift/libswiftCore.dylib 

BTW... thanks for the app! The older macs running older macos with older batteries are the ones that really might be helped by this. I have seen quite a few with swollen batteries likely due to overheating/overcharging. (The darned Aldente app won't work on older macs as it requires 10.15 or newer ;-)

Anyways, when I added the snippet below to main.scpt it worked ok for me in some limited testing. YMMV ;-)

var app = Application.currentApplication()
app.includeStandardAdditions = true

// (snip) Test and warn if SwiftRuntimeForCommandLineTools.dmg is needed (like for 10.14.3 or earlier)
// See https://github.com/zackelia/bclm/issues/6
var path = Path('/usr/lib/swift/libswiftCore.dylib');
var finderApp = Application("Finder");
var status = finderApp.exists(path);
var url = `https://support.apple.com/kb/DL1998?locale=en_US`
// app.displayAlert(status)
if (status == false) {
	if (app.displayAlert(`For 10.14.3 and earlier please install SwiftRuntimeForCommandLineTools.dmg `, {
		message: `Please do small one-time-only install. Would you like to open the Apple download site?`,
		as: 'critical',
		buttons: ['Remind Me Later', 'Open site'],
		defaultButton: 'Open site'
	}).buttonReturned === 'Open site') {
		app.doShellScript(`open '${url}'`)
	}
}
// (\snip) End of test and warn if SwiftRuntimeForCommandLineTools.dmg is needed  

var version = 'v' + app.doShellScript(`defaults read '${app.pathTo(this)}/Contents/Info.plist' CFBundleShortVersionString`)
var latestVersion = app.doShellScript(`curl -s 'https://api.github.com/repos/godly-devotion/charge-limiter/releases/latest' | awk -F '"' '/tag_name/{print $4}'`)
var url = `https://github.com/godly-devotion/charge-limiter/releases/latest`

If anyone knows a better way than using Finder to test that file /usr/lib/swift/libswiftCore.dylib exists, then that might avoid possible issue where you might have to set finder to show all files. Tho in my quick and dirty testing, I do not think I had to do this:

   defaults write com.apple.Finder AppleShowAllFiles -bool YES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant