Created
September 23, 2018 17:36
-
-
Save IARI/4279ac8291b7cd5740c4c06db3a0037e to your computer and use it in GitHub Desktop.
Operating system related tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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