Skip to content

Instantly share code, notes, and snippets.

@IARI
Created September 23, 2018 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IARI/4279ac8291b7cd5740c4c06db3a0037e to your computer and use it in GitHub Desktop.
Save IARI/4279ac8291b7cd5740c4c06db3a0037e to your computer and use it in GitHub Desktop.
Operating system related tools
package com.julianjarecki.latextemplates.lib
import java.io.File
import java.util.logging.Logger
enum class OS {
Windows, OSX, Linux;
companion object {
val current: OS = System.getProperty("os.name")
.toLowerCase().run {
when {
startsWith("windows") -> Windows
startsWith("linux") -> Linux
else -> OSX
}
}
}
}
fun File.openInExplorer() {
when (OS.current) {
OS.Windows -> "explorer.exe /select,${absolutePath}".runCommand(parentFile)
else -> Logger.getGlobal().info("currently not implemented on ${OS.current} (os.name = ${System.getProperty("os.name")})")
}
}
fun File.openWithDefaultApp() {
when (OS.current) {
OS.Windows -> "cmd /c \"start ${absolutePath}\"".runCommand(parentFile)
else -> Logger.getGlobal().info("currently not implemented on ${OS.current} (os.name = ${System.getProperty("os.name")})")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment