github.com/ChicK00o/awgo@v0.29.4/util/util.go (about) 1 // Copyright (c) 2018 Dean Jackson <deanishe@deanishe.net> 2 // MIT Licence - http://opensource.org/licenses/MIT 3 4 /* 5 6 Package util contains general helper functions for workflow (library) authors. 7 8 The functions can be divided into roughly three groups: paths, formatting 9 and scripting. 10 11 12 Paths 13 14 There are a couple of convenience path functions, MustExist and 15 ClearDirectory. 16 17 18 Formatting 19 20 PrettyPath for user-friendly paths, and the Pad* functions for padding 21 strings. 22 23 Scripting 24 25 QuoteAS quotes strings for insertion into AppleScript code and there 26 are several Run* functions for executing script code and files. 27 28 Run() // run a script file or executable & return output 29 RunAS() // run AppleScript code & return output 30 RunJS() // run JXA code & return output 31 RunCmd() // run *exec.Cmd & return output 32 33 Run takes the path to a script or executable. If file is executable, 34 it runs the file directly. If it's a script file, it tries to guess the 35 appropriate interpreter. 36 37 See Runner for more information. 38 39 */ 40 package util 41 42 import ( 43 "log" 44 "time" 45 ) 46 47 // Timed logs the duration since start & title. Use it with defer. 48 // 49 // func doSomething() { 50 // defer Timed(time.Now(), "long running task") 51 // // do thing here 52 // // and another thing 53 // } 54 // // Output: ... long running task 55 // 56 func Timed(start time.Time, title string) { 57 log.Printf("%s \U000029D7 %s", time.Since(start), title) 58 }