mac
package main import ( "fmt" "os" "strings" "os/exec" ) func show() { cmd := exec.Command("/bin/bash","-c","defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder") _, err := cmd.Output() if err != nil { fmt.Println("运行失败: " + err.Error()) return }else { fmt.Println("运行成功") } } func hide() { cmd := exec.Command("/bin/bash","-c","defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder") _, err := cmd.Output() if err != nil { fmt.Println("运行失败: " + err.Error()) return }else { fmt.Println("运行成功") } } func main() { argNum := len(os.Args) if argNum == 1{ fmt.Println("缺少参数, show或hide") return } shouldShow := os.Args[1] if strings.EqualFold("show",shouldShow){ show() } if strings.EqualFold("hide",shouldShow){ hide() } }
时间: 2024-10-06 14:12:23