@@ -16,44 +16,28 @@ extension CodeEditCLI {
1616 )
1717
1818 func run( ) throws {
19- // Run an apple script to find CodeEdit.app
20- let pathData = try codeEditURLData ( )
19+ // Print the cli version
20+ print ( " CodeEditCLI: \t \( CLI_VERSION) " )
21+
22+ // File URL of CodeEdit.app
23+ let appURL = URL ( fileURLWithPath: " /Applications/CodeEdit.app " )
2124
2225 // Check if there is an Info.plist inside CodeEdit.app
2326 // Then get the version number and print it out
2427 //
2528 // This will fail when CodeEdit.app is not installed
26- if let url = infoPlistUrl ( pathData : pathData ) ,
29+ if let url = infoPlistUrl ( appURL ) ,
2730 let plist = NSDictionary ( contentsOf: url) as? [ String : Any ] ,
2831 let version = plist [ " CFBundleShortVersionString " ] as? String {
2932 print ( " CodeEdit.app: \t \( version) " )
3033 } else {
3134 print ( " CodeEdit.app is not installed. " )
3235 }
33-
34- // Print the cli version
35- print ( " CodeEditCLI: \t \( CLI_VERSION) " )
36- }
37-
38- private func codeEditURLData( ) throws -> Data {
39- let task = Process ( )
40- let pipe = Pipe ( )
41- task. standardOutput = pipe
42- task. launchPath = " /usr/bin/osascript "
43-
44- task. arguments = [ " -e " ]
45- task. arguments? . append ( " POSIX path of (path to application \" CodeEdit \" ) " )
46-
47- try task. run ( )
48-
49- return pipe. fileHandleForReading. readDataToEndOfFile ( )
5036 }
5137
52- private func infoPlistUrl( pathData: Data ) -> URL ? {
53- if let path = String ( data: pathData, encoding: . utf8) {
54- let url = URL ( fileURLWithPath: path. trimmingCharacters ( in: . whitespacesAndNewlines) )
55- . appendingPathComponent ( " Contents " )
56- . appendingPathComponent ( " Info.plist " )
38+ private func infoPlistUrl( _ url: URL ? ) -> URL ? {
39+ if let url = url? . appendingPathComponent ( " Contents " )
40+ . appendingPathComponent ( " Info.plist " ) {
5741 return url
5842 } else {
5943 return nil
0 commit comments