├── Dock Master.xcodeproj ├── xcuserdata │ └── mpage.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── Dock Master.xcscheme ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── mpage.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── project.pbxproj ├── Dock Master ├── main.swift ├── FileOperations.swift └── Dock.swift ├── README.md └── LICENSE /Dock Master.xcodeproj/xcuserdata/mpage.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Dock Master.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Dock Master.xcodeproj/project.xcworkspace/xcuserdata/mpage.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Error-freeIT/Dock-Master/HEAD/Dock Master.xcodeproj/project.xcworkspace/xcuserdata/mpage.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Dock Master.xcodeproj/xcuserdata/mpage.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Dock Master.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AEB5BE3C1D001C970074DC25 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Dock Master/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Dock Master 4 | // 5 | // Created by Michael Page on 2/06/2016. 6 | // Copyright © 2016 Error-free IT. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | var generateProfile = Bool() 12 | var generatePackageTemplate = Bool() 13 | var templateFile = String() 14 | var target = String() 15 | 16 | func displayHelp() { 17 | print("Dock Master v0.9\n" + 18 | "Created by Michael Page on 26/06/2016.\n" + 19 | "Copyright © 2016 Error-free IT. All rights reserved.\n\n" + 20 | 21 | "Dock Master is a tool for generating dock profiles and dock packages.\n\n" + 22 | 23 | "Synopsis: dockmaster [-m | -p] -t template_file target\n\n" + 24 | 25 | "Arguments:\n" + 26 | " -h, --help Display this help.\n" + 27 | " -m, --mobileconfig Output dock profile (mobileconfig) file.\n" + 28 | " -p, --package Output dock package template.\n" + 29 | " -t, --template Path to a Dock Master template file.\n\n" + 30 | 31 | "Examples:\n" + 32 | " Generate a profile:\n" + 33 | " dockmaster -m -t dockmastertemplate.plist profile.mobileconfig\n\n" + 34 | 35 | " Generate a package template:\n" + 36 | " dockmaster -p -t dockmastertemplate.plist /destination/") 37 | } 38 | 39 | 40 | if Process.arguments.count < 2 { 41 | // No arguments were provided. 42 | displayHelp() 43 | } else { 44 | var input = Process.arguments 45 | input.removeFirst() 46 | var arguments = input 47 | 48 | if let lastArgument = arguments.last { 49 | target = lastArgument 50 | } 51 | 52 | for (index,argument) in arguments.enumerate() { 53 | 54 | switch argument { 55 | case "-h", "--help": 56 | displayHelp() 57 | case "-m", "--mobileconfig": 58 | generateProfile = true 59 | case "-p", "--package": 60 | generatePackageTemplate = true 61 | case "-t", "--template": 62 | // Assign the argument after -t or --template to templateFile. 63 | var templateFileIndex = index+1 64 | // Ensure next index is within arguments array. 65 | if arguments.count > templateFileIndex { 66 | templateFile = arguments[templateFileIndex] 67 | } 68 | default: break 69 | } 70 | 71 | } 72 | } 73 | 74 | if templateFile.isEmpty { 75 | print("Error: No Dock Master template file specified!") 76 | } else if !generateProfile && !generatePackageTemplate { 77 | print("Error: An output type (--mobileconfig or --package) was not specified!") 78 | }else { 79 | let loadedDock = Dock().loadDockTemplate(templateFile) 80 | 81 | if generateProfile { 82 | FileOperation().writeDictionaryToFile(loadedDock.generateProfileXML(), filename: target) 83 | } else if generatePackageTemplate { 84 | FileOperation().writePackageTemplate(loadedDock, directory: target) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Dock Master.xcodeproj/xcuserdata/mpage.xcuserdatad/xcschemes/Dock Master.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dock Master 2 | 3 | _An Extensive OS X Dock Profile/Package Tool_ 4 | 5 | > ## Dock Master Has Evolved — Introducing **Dock Composer** 6 | > 7 | > Over the past few years, I’ve been steadily working on a complete rewrite of Dock Master in my spare time. 8 | > **Dock Composer** is the result — a fully native macOS app with a heap of new features, making it easier than ever to build and customise your Dock. 9 | > 10 | > 🎉 You can grab it today on the Mac App Store: 11 | > **https://apps.apple.com/au/app/dock-composer/id6751523907?mt=12** 12 | > 13 | > _This repository is now archived and no longer maintained._ 14 | 15 | #### Introduction 16 | 17 | Dock Master is a tool for generating dock profiles and dock packages. 18 | 19 | Originally Dock Master was written in PHP and hosted on the [Error-free IT website](http://errorfreeit.com.au). Due to the surprising demand for an offline tool I have rewritten Dock Master in Apple's new programming language [Swift](https://github.com/apple/swift). 20 | 21 | #### Usage 22 | 23 | In its current form, Dock Master is a command-line tool. 24 | 25 | Note: If you are uncomfortable with the command-line or just want something more user-friendly try out the web interface of Dock Master [here](http://errorfreeit.com.au/blog/2015/4/28/dock-master). 26 | 27 | 1. Install the [latest Dock Master.pkg](https://github.com/Error-freeIT/Dock-Master/releases/latest). 28 | 29 | 2. Customise the [dockmastertemplate.plist](https://github.com/Error-freeIT/Dock-Master/releases/download/v0.7/dockmastertemplate.plist) in Xcode or your favourite text editor. See the Dock Master Template Options table below for further details. 30 | 31 | 3. Open Terminal: 32 | 33 | * To generate a profile: `dockmaster -m -t dockmastertemplate.plist /destination/profile.mobileconfig` 34 | * To generate a package template: `dockmaster -p -t dockmastertemplate.plist /destination/` 35 | 36 | ##### Packages vs Profiles 37 | * Profiles are the standard approach for enforcing preferences in OS X. 38 | * Dock Master packages are great for deploying an inital base dock that allows users to further customise as desired. 39 | 40 | #### Dock Master Template Options 41 | 42 | | | | | | 43 | |-----------------------------------|---------------------------------------------------------------------------------|--------------------|------------------------------| 44 | | Option | Description | Applies to Package | Default | 45 | | display_name | Name of the profile displayed to the end user | TRUE | Custom Dock | 46 | | organization | Organisation name (e.g. Error-free IT) | FALSE | | 47 | | description | Profile description | FALSE | | 48 | | scope | System or User | FALSE | System | 49 | | contents_immutable | Prevent dock from being modified | TRUE | FALSE | 50 | | merge_with_existing_dock | Merge with any existing dock items | TRUE | FALSE | 51 | | add_network_home | Adds the user's network home folder to the dock | TRUE | FALSE | 52 | | tile_size | Maximum icon size. Value: 1-256 | TRUE | 68 | 53 | | tile_size_immutable | Lock tile_size | TRUE | FALSE | 54 | | magnification | Magnification when hovering over items | TRUE | FALSE | 55 | | magnification_immutable | Lock magnification | TRUE | FALSE | 56 | | magnification_size | The level of magnification when hovering over items. Value: 1-256 | TRUE | 128 | 57 | | magnification_size_immutable | Lock magnification_size | TRUE | FALSE | 58 | | position | Position of the dock. Value: left, bottom or right | TRUE | bottom | 59 | | position_immutable | Lock position | TRUE | FALSE | 60 | | minimize_effect | Minimise effect. Value: genie or scale | TRUE | genie | 61 | | minimize_effect_immutable | Lock minimize_effect | TRUE | FALSE | 62 | | animate_app_launch | Applications animate (bounce) on open | TRUE | TRUE | 63 | | animate_app_launch_immutable | Lock animate_app_launch | TRUE | FALSE | 64 | | auto_hide | Dock hides and only appears on hover | TRUE | FALSE | 65 | | show_process_indicators | Display a dot to indicate the application is running | TRUE | TRUE | 66 | | show_process_indicators_immutable | Lock show_process_indicators | TRUE | FALSE | 67 | | minimize_into_app | Windows minimise into their respective app icon | TRUE | FALSE | 68 | | minimize_into_app_immutable | Lock minimize_into_app | TRUE | FALSE | 69 | | cfurl_string | Path to App or resource | TRUE | | 70 | | removable | Dock item can be removed | TRUE | FALSE | 71 | | label | Specify a label (e.g. Network Resources) | TRUE | Extracted from cfurl_string | 72 | | arrangement | Sort by. Value: 1=Name, 2=Date Added, 3=Date Modified, 4=Date Created or 5=Kind | TRUE | 1 | 73 | | show_as | View content as. Value: 1=Fan, 2=Grid, 3=List or 4=Automatic | TRUE | 4 | 74 | | display_as | Display as. Value: 1=Folder or 2=Stack | TRUE | 2 | 75 | -------------------------------------------------------------------------------- /Dock Master/FileOperations.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileOperations.swift 3 | // Dock Master 4 | // 5 | // Created by Michael Page on 27/05/2016. 6 | // Copyright © 2016 Error-free IT. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | // This class is primarily for loading and saving plist/mobileconfig files. 13 | class FileOperation { 14 | 15 | func readDictionaryFromFile(filename: String) -> NSDictionary? { 16 | 17 | let fileManager = NSFileManager.defaultManager() 18 | 19 | // If file exists return the contents as a dictionary. 20 | if fileManager.fileExistsAtPath(filename) { 21 | return NSDictionary(contentsOfFile: filename) 22 | } else { 23 | print("Error: \"\(filename)\" could not be opened!") 24 | return nil 25 | } 26 | 27 | } 28 | 29 | func writeDictionaryToFile(dictionary: NSDictionary, filename: String) { 30 | 31 | // Write dictionary into plist file. 32 | dictionary.writeToFile(filename, atomically: false) 33 | 34 | } 35 | 36 | func writeStringToFile(string: String, filename: String, makeExecutable: Bool = false) { 37 | 38 | do { 39 | // Write dictionary into plist file. 40 | try string.writeToFile(filename, atomically: false, encoding: NSUTF8StringEncoding) 41 | 42 | if makeExecutable { 43 | let fileManager = NSFileManager.defaultManager() 44 | // A decimal value of 493 is equal to an octal value of 755 (rwxr-xr-x). 45 | let attributes = ["NSFilePosixPermissions":493] 46 | try fileManager.setAttributes(attributes, ofItemAtPath: filename) 47 | } 48 | 49 | } catch let error as NSError { 50 | print(error.description) 51 | } 52 | 53 | } 54 | 55 | func writePackageTemplate(dock: Dock, directory: String) { 56 | 57 | let makePackageScript = "#!/bin/bash\n\n" + 58 | 59 | "# Name of the package.\n" + 60 | "NAME=\"\(dock.payloadIdentifier)\"\n\n" + 61 | 62 | "# Once installed the identifier is used as the filename for a receipt files in /var/db/receipts/.\n" + 63 | "IDENTIFIER=\"au.com.errorfreeit.dockmaster.${NAME}\"\n\n" + 64 | 65 | "# Package version.\n" + 66 | "VERSION=\"\(dock.packageVersion)\"\n\n" + 67 | 68 | "# The User Template directory is applied to new user accounts. The dock plist placed in this directory will be copied into new accounts.\n" + 69 | "INSTALL_LOCATION=\"/System/Library/User Template/English.lproj/Library/Preferences/\"\n\n" + 70 | 71 | "# Change into the same directory as this script.\n" + 72 | "cd \"$(/usr/bin/dirname \"$0\")\"\n\n" + 73 | 74 | "# Store the path containing this script.\n" + 75 | "SCRIPT_PATH=\"$(pwd)\"\n\n" + 76 | 77 | "# Build the package.\n" + 78 | "/usr/bin/pkgbuild \\\n" + 79 | " --root \"${SCRIPT_PATH}/payload/\" \\\n" + 80 | " --install-location \"$INSTALL_LOCATION\" \\\n" + 81 | " --scripts \"$SCRIPT_PATH/scripts/\" \\\n" + 82 | " --identifier \"$IDENTIFIER\" \\\n" + 83 | " --version \"$VERSION\" \\\n" + 84 | " \"${SCRIPT_PATH}/package/${NAME}-${VERSION}.pkg\"" 85 | 86 | 87 | let applyDockToExisitingUsers = dock.packageAppliesToExistingUsers ? "true" : "false" 88 | 89 | let postInstallScript = "#!/bin/bash\n\n" + 90 | 91 | "# Apply dock to existing user accounts.\n" + 92 | "APPLY_DOCK_TO_EXISTING_USERS=\(applyDockToExisitingUsers)\n\n" + 93 | 94 | "### NOTHING BELOW THIS LINE NEEDS TO CHANGE ###\n\n" + 95 | 96 | "# A dock plist placed in the User Template directory is applied to new user accounts.\n" + 97 | "USER_TEMPLATE_DOCK_PLIST=\"/System/Library/User Template/English.lproj/Library/Preferences/com.apple.dock.plist\"\n\n" + 98 | 99 | "# Currently logged in user.\n" + 100 | "CURRENTLY_LOGGED_IN_USER=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')\n\n" + 101 | 102 | "if [[ \"$APPLY_DOCK_TO_EXISTING_USERS\" == \"true\" ]]\n" + 103 | "then\n" + 104 | " # Output local home directory path (/Users/username).\n" + 105 | " for USER_HOME in /Users/*\n" + 106 | " do\n" + 107 | " # Extract account name (a.k.a. username) from home directory path.\n" + 108 | " ACCOUNT_NAME=$(/usr/bin/basename \"${USER_HOME}\")\n\n" + 109 | 110 | " # If account name is not \"Shared\".\n" + 111 | " if [[ \"$ACCOUNT_NAME\" != \"Shared\" ]]\n" + 112 | " then\n" + 113 | " USER_DOCK_PLIST=\"${USER_HOME}/Library/Preferences/com.apple.dock.plist\"\n\n" + 114 | 115 | " # If the account already contains a dock plist.\n" + 116 | " if [[ -f \"$USER_DOCK_PLIST\" ]]\n" + 117 | " then\n" + 118 | " echo \"Removing existing user dock plist.\"\n" + 119 | " /usr/bin/defaults delete \"$USER_DOCK_PLIST\"\n" + 120 | " fi\n\n" + 121 | 122 | " echo \"Copying the latest dock plist into place.\"\n" + 123 | " cp \"$USER_TEMPLATE_DOCK_PLIST\" \"$USER_DOCK_PLIST\"\n\n" + 124 | 125 | " echo \"Updating permissions to match user (${ACCOUNT_NAME}).\"\n" + 126 | " /usr/sbin/chown -R \"$ACCOUNT_NAME\" \"$USER_DOCK_PLIST\"\n\n" + 127 | 128 | " # Reboot the dock if a user is currently logged in.\n" + 129 | " if [[ \"$CURRENTLY_LOGGED_IN_USER\" == \"$ACCOUNT_NAME\" ]]\n" + 130 | " then\n" + 131 | " # Update cached dock plist.\n" + 132 | " /usr/bin/sudo -u \"$ACCOUNT_NAME\" /usr/bin/defaults read \"$USER_DOCK_PLIST\"\n" + 133 | " # Relaunch the dock process.\n" + 134 | " /usr/bin/killall Dock\n" + 135 | " fi\n" + 136 | " fi\n" + 137 | " done\n" + 138 | "fi" 139 | 140 | 141 | let fileManager = NSFileManager.defaultManager() 142 | 143 | do { 144 | // Create package, plist and script directories. 145 | try fileManager.createDirectoryAtPath("\(directory)/package", withIntermediateDirectories: true, attributes: nil) 146 | try fileManager.createDirectoryAtPath("\(directory)/payload", withIntermediateDirectories: true, attributes: nil) 147 | try fileManager.createDirectoryAtPath("\(directory)/scripts", withIntermediateDirectories: true, attributes: nil) 148 | 149 | // Generate dock plist. 150 | FileOperation().writeDictionaryToFile(dock.generatePlistXML(),filename: "\(directory)/payload/com.apple.dock.plist") 151 | 152 | // Write makepackage.command into root of directory. 153 | FileOperation().writeStringToFile(makePackageScript, filename: "\(directory)/makepackage.command", makeExecutable: true) 154 | 155 | // Write postinstall into script directory. 156 | FileOperation().writeStringToFile(postInstallScript, filename: "\(directory)/scripts/postinstall", makeExecutable: true) 157 | 158 | } catch let error as NSError { 159 | print(error.description) 160 | } 161 | 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /Dock Master.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | AEB5BE411D001C970074DC25 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB5BE401D001C970074DC25 /* main.swift */; }; 11 | AEB5BE481D001CB70074DC25 /* Dock.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB5BE471D001CB70074DC25 /* Dock.swift */; }; 12 | AEB5BE4A1D001D200074DC25 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB5BE491D001D200074DC25 /* FileOperations.swift */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | AEB5BE3B1D001C970074DC25 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = /usr/share/man/man1/; 20 | dstSubfolderSpec = 0; 21 | files = ( 22 | ); 23 | runOnlyForDeploymentPostprocessing = 1; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | AEB5BE3D1D001C970074DC25 /* dockmaster */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = dockmaster; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | AEB5BE401D001C970074DC25 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 30 | AEB5BE471D001CB70074DC25 /* Dock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dock.swift; sourceTree = ""; }; 31 | AEB5BE491D001D200074DC25 /* FileOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileOperations.swift; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | AEB5BE3A1D001C970074DC25 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | AEB5BE341D001C970074DC25 = { 46 | isa = PBXGroup; 47 | children = ( 48 | AEB5BE3F1D001C970074DC25 /* Dock Master */, 49 | AEB5BE3E1D001C970074DC25 /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | AEB5BE3E1D001C970074DC25 /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | AEB5BE3D1D001C970074DC25 /* dockmaster */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | AEB5BE3F1D001C970074DC25 /* Dock Master */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | AEB5BE401D001C970074DC25 /* main.swift */, 65 | AEB5BE471D001CB70074DC25 /* Dock.swift */, 66 | AEB5BE491D001D200074DC25 /* FileOperations.swift */, 67 | ); 68 | path = "Dock Master"; 69 | sourceTree = ""; 70 | }; 71 | /* End PBXGroup section */ 72 | 73 | /* Begin PBXNativeTarget section */ 74 | AEB5BE3C1D001C970074DC25 /* dockmaster */ = { 75 | isa = PBXNativeTarget; 76 | buildConfigurationList = AEB5BE441D001C970074DC25 /* Build configuration list for PBXNativeTarget "dockmaster" */; 77 | buildPhases = ( 78 | AEB5BE391D001C970074DC25 /* Sources */, 79 | AEB5BE3A1D001C970074DC25 /* Frameworks */, 80 | AEB5BE3B1D001C970074DC25 /* CopyFiles */, 81 | ); 82 | buildRules = ( 83 | ); 84 | dependencies = ( 85 | ); 86 | name = dockmaster; 87 | productName = "Dock Master"; 88 | productReference = AEB5BE3D1D001C970074DC25 /* dockmaster */; 89 | productType = "com.apple.product-type.tool"; 90 | }; 91 | /* End PBXNativeTarget section */ 92 | 93 | /* Begin PBXProject section */ 94 | AEB5BE351D001C970074DC25 /* Project object */ = { 95 | isa = PBXProject; 96 | attributes = { 97 | LastSwiftUpdateCheck = 0730; 98 | LastUpgradeCheck = 0730; 99 | ORGANIZATIONNAME = "Error-free IT"; 100 | TargetAttributes = { 101 | AEB5BE3C1D001C970074DC25 = { 102 | CreatedOnToolsVersion = 7.3; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = AEB5BE381D001C970074DC25 /* Build configuration list for PBXProject "Dock Master" */; 107 | compatibilityVersion = "Xcode 3.2"; 108 | developmentRegion = English; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | ); 113 | mainGroup = AEB5BE341D001C970074DC25; 114 | productRefGroup = AEB5BE3E1D001C970074DC25 /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | AEB5BE3C1D001C970074DC25 /* dockmaster */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXSourcesBuildPhase section */ 124 | AEB5BE391D001C970074DC25 /* Sources */ = { 125 | isa = PBXSourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | AEB5BE481D001CB70074DC25 /* Dock.swift in Sources */, 129 | AEB5BE4A1D001D200074DC25 /* FileOperations.swift in Sources */, 130 | AEB5BE411D001C970074DC25 /* main.swift in Sources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXSourcesBuildPhase section */ 135 | 136 | /* Begin XCBuildConfiguration section */ 137 | AEB5BE421D001C970074DC25 /* Debug */ = { 138 | isa = XCBuildConfiguration; 139 | buildSettings = { 140 | ALWAYS_SEARCH_USER_PATHS = NO; 141 | CLANG_ANALYZER_NONNULL = YES; 142 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 143 | CLANG_CXX_LIBRARY = "libc++"; 144 | CLANG_ENABLE_MODULES = YES; 145 | CLANG_ENABLE_OBJC_ARC = YES; 146 | CLANG_WARN_BOOL_CONVERSION = YES; 147 | CLANG_WARN_CONSTANT_CONVERSION = YES; 148 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 149 | CLANG_WARN_EMPTY_BODY = YES; 150 | CLANG_WARN_ENUM_CONVERSION = YES; 151 | CLANG_WARN_INT_CONVERSION = YES; 152 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 153 | CLANG_WARN_UNREACHABLE_CODE = YES; 154 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 155 | CODE_SIGN_IDENTITY = "-"; 156 | COPY_PHASE_STRIP = NO; 157 | DEBUG_INFORMATION_FORMAT = dwarf; 158 | ENABLE_STRICT_OBJC_MSGSEND = YES; 159 | ENABLE_TESTABILITY = YES; 160 | GCC_C_LANGUAGE_STANDARD = gnu99; 161 | GCC_DYNAMIC_NO_PIC = NO; 162 | GCC_NO_COMMON_BLOCKS = YES; 163 | GCC_OPTIMIZATION_LEVEL = 0; 164 | GCC_PREPROCESSOR_DEFINITIONS = ( 165 | "DEBUG=1", 166 | "$(inherited)", 167 | ); 168 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 169 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 170 | GCC_WARN_UNDECLARED_SELECTOR = YES; 171 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 172 | GCC_WARN_UNUSED_FUNCTION = YES; 173 | GCC_WARN_UNUSED_VARIABLE = YES; 174 | MACOSX_DEPLOYMENT_TARGET = 10.11; 175 | MTL_ENABLE_DEBUG_INFO = YES; 176 | ONLY_ACTIVE_ARCH = YES; 177 | SDKROOT = macosx; 178 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 179 | }; 180 | name = Debug; 181 | }; 182 | AEB5BE431D001C970074DC25 /* Release */ = { 183 | isa = XCBuildConfiguration; 184 | buildSettings = { 185 | ALWAYS_SEARCH_USER_PATHS = NO; 186 | CLANG_ANALYZER_NONNULL = YES; 187 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 188 | CLANG_CXX_LIBRARY = "libc++"; 189 | CLANG_ENABLE_MODULES = YES; 190 | CLANG_ENABLE_OBJC_ARC = YES; 191 | CLANG_WARN_BOOL_CONVERSION = YES; 192 | CLANG_WARN_CONSTANT_CONVERSION = YES; 193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 194 | CLANG_WARN_EMPTY_BODY = YES; 195 | CLANG_WARN_ENUM_CONVERSION = YES; 196 | CLANG_WARN_INT_CONVERSION = YES; 197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 198 | CLANG_WARN_UNREACHABLE_CODE = YES; 199 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 200 | CODE_SIGN_IDENTITY = "-"; 201 | COPY_PHASE_STRIP = NO; 202 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 203 | ENABLE_NS_ASSERTIONS = NO; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu99; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 208 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 209 | GCC_WARN_UNDECLARED_SELECTOR = YES; 210 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 211 | GCC_WARN_UNUSED_FUNCTION = YES; 212 | GCC_WARN_UNUSED_VARIABLE = YES; 213 | MACOSX_DEPLOYMENT_TARGET = 10.11; 214 | MTL_ENABLE_DEBUG_INFO = NO; 215 | SDKROOT = macosx; 216 | }; 217 | name = Release; 218 | }; 219 | AEB5BE451D001C970074DC25 /* Debug */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | PRODUCT_NAME = "$(TARGET_NAME)"; 223 | }; 224 | name = Debug; 225 | }; 226 | AEB5BE461D001C970074DC25 /* Release */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | PRODUCT_NAME = "$(TARGET_NAME)"; 230 | }; 231 | name = Release; 232 | }; 233 | /* End XCBuildConfiguration section */ 234 | 235 | /* Begin XCConfigurationList section */ 236 | AEB5BE381D001C970074DC25 /* Build configuration list for PBXProject "Dock Master" */ = { 237 | isa = XCConfigurationList; 238 | buildConfigurations = ( 239 | AEB5BE421D001C970074DC25 /* Debug */, 240 | AEB5BE431D001C970074DC25 /* Release */, 241 | ); 242 | defaultConfigurationIsVisible = 0; 243 | defaultConfigurationName = Release; 244 | }; 245 | AEB5BE441D001C970074DC25 /* Build configuration list for PBXNativeTarget "dockmaster" */ = { 246 | isa = XCConfigurationList; 247 | buildConfigurations = ( 248 | AEB5BE451D001C970074DC25 /* Debug */, 249 | AEB5BE461D001C970074DC25 /* Release */, 250 | ); 251 | defaultConfigurationIsVisible = 0; 252 | defaultConfigurationName = Release; 253 | }; 254 | /* End XCConfigurationList section */ 255 | }; 256 | rootObject = AEB5BE351D001C970074DC25 /* Project object */; 257 | } 258 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Dock Master/Dock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Dock.swift 3 | // Dock Master 4 | // 5 | // Created by Michael Page on 27/05/2016. 6 | // Copyright © 2016 Error-free IT. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | class DockItem { 13 | 14 | // tile-type will either be directory-tile: local directory, file-tile: application/webloc, url-tile: URL or network share. 15 | var tileType: String? { 16 | get { 17 | func returnTileType(target: String) -> String { 18 | // If the path contains "://" (CFURL). 19 | if target.rangeOfString("://") != nil { 20 | return "url-tile" 21 | // If the target has a file extension. 22 | } else if NSURL(fileURLWithPath: target).pathExtension != "" { 23 | return "file-tile" 24 | } else { 25 | return "directory-tile" 26 | } 27 | } 28 | if let unwrappedCfurlString = cfurlString { 29 | return returnTileType(unwrappedCfurlString) 30 | } else if let unwrappedHomeDirectoryRelative = homeDirectoryRelative { 31 | return returnTileType(unwrappedHomeDirectoryRelative) 32 | } else { 33 | return nil 34 | } 35 | } 36 | } 37 | 38 | // If the dock items cfurlString starts with ~ this key will be set to the value of cfurlString, 39 | private var _homeDirectoryRelative: String = "" 40 | var homeDirectoryRelative: String? { 41 | get { 42 | if _homeDirectoryRelative != "" { 43 | return _homeDirectoryRelative 44 | } else { 45 | return nil 46 | } 47 | } 48 | set { 49 | // If newValue is not nil. 50 | if let unwrappedNewValue = newValue { 51 | // Store the new value in _displayAs. 52 | _homeDirectoryRelative = unwrappedNewValue 53 | } else { 54 | // Set _homeDirectoryRelative to "" to reflect no preference. 55 | _homeDirectoryRelative = "" 56 | } 57 | } 58 | } 59 | 60 | // Path to resource (e.g. /Applications/App Store.app, smb://server/staffresources, http://www.google.com), 61 | private var _cfurlString: String = "" 62 | var cfurlString: String? { 63 | get { 64 | if _cfurlString.hasPrefix("~") { 65 | // Dock item is home directory relative. 66 | self.homeDirectoryRelative = _cfurlString 67 | return nil 68 | // If _cfurlString is no longer it's inital value (""). 69 | } else if _cfurlString != "" { 70 | // Return the value it has been set to. 71 | return _cfurlString 72 | } else { 73 | return nil 74 | } 75 | } 76 | set { 77 | // If newValue is not nil. 78 | if let unwrappedNewValue = newValue { 79 | // Store the new value in _displayAs. 80 | _cfurlString = unwrappedNewValue 81 | } else { 82 | // Set _cfurlString to "" to reflect no preference. 83 | _cfurlString = "" 84 | } 85 | } 86 | } 87 | 88 | // cfurlStringType depends on the path style: 0: /Applications/Safari.app, 15: file:///Applications/Safari.app/. 89 | var cfurlStringType: Int? { 90 | get { 91 | if let unwrappedCfurlString = cfurlString { 92 | // If dock item is not home directory relative, as they do not have a _CFURLStringType key. 93 | if !unwrappedCfurlString.hasPrefix("~") { 94 | // If the path contains :// it's a CFURL string type 15. 95 | if unwrappedCfurlString.rangeOfString("://") != nil { 96 | return 15 97 | } else { 98 | return 0 99 | } 100 | } 101 | } 102 | return nil 103 | } 104 | } 105 | 106 | // arrangement (sort by) will be 1: name, 2: date added, 3: date modified, 4: date created or 5: kind. 107 | // _arrangement is used to backup the computed property. 108 | private var _arrangement: Int = 0 109 | var arrangement: Int? { 110 | get { 111 | // If _arrangement is no longer it's inital value (0). 112 | if _arrangement != 0 { 113 | // Return the value it has been set to. 114 | return _arrangement 115 | } else if tileType == "directory-tile" && _arrangement == 0 { 116 | // It hasn't been set, but is a directory, return the default value (sort by name). 117 | return 1 118 | } else { 119 | return nil 120 | } 121 | } 122 | set { 123 | // If newValue is not nil. 124 | if let unwrappedNewValue = newValue { 125 | // Store the new value in _arrangement. 126 | _arrangement = unwrappedNewValue 127 | } else { 128 | // Set _arrangement to 0 to reflect no preference. 129 | _arrangement = 0 130 | } 131 | } 132 | } 133 | 134 | // showAs (view content as) will be 1: fan, 2: grid, 3: list or 4: automatic. 135 | // _showAs is used to backup the computed property. 136 | private var _showAs: Int = 0 137 | var showAs: Int? { 138 | get { 139 | // If _showAs is no longer it's inital value (0). 140 | if _showAs != 0 { 141 | // Return the value it has been set to. 142 | return _showAs 143 | } else if tileType == "directory-tile" && _showAs == 0 { 144 | // It hasn't been set, but is a directory, return the default value (view content as automatic). 145 | return 4 146 | } else { 147 | return nil 148 | } 149 | } 150 | set { 151 | // If newValue is not nil. 152 | if let unwrappedNewValue = newValue { 153 | // Store the new value in _showAs. 154 | _showAs = unwrappedNewValue 155 | } else { 156 | // Set _showAs to 0 to reflect no preference. 157 | _showAs = 0 158 | } 159 | } 160 | } 161 | 162 | // displayAs will either be 1: folder or 2: stack. 163 | // _displayAs is used to backup the computed property. 164 | private var _displayAs: Int = 0 165 | var displayAs: Int? { 166 | get { 167 | // If _displayAs is no longer it's inital value (0). 168 | if _displayAs != 0 { 169 | // Return the value it has been set to. 170 | return _displayAs 171 | } else if tileType == "directory-tile" && _displayAs == 0 { 172 | // It hasn't been set, but is a directory, return the default value (display as a stack). 173 | return 2 174 | } else { 175 | return nil 176 | } 177 | } 178 | set { 179 | // If newValue is not nil. 180 | if let unwrappedNewValue = newValue { 181 | // Store the new value in _displayAs. 182 | _displayAs = unwrappedNewValue 183 | } else { 184 | // Set _displayAs to 0 to reflect no preference. 185 | _displayAs = 0 186 | } 187 | } 188 | } 189 | 190 | // Optional dock item label applied to URLs, shares and home directory relative paths. 191 | // _label is used to backup the computed property. 192 | private var _label: String = "" 193 | var label: String? { 194 | get { 195 | // If _label is no longer it's inital value (""). 196 | if _label != "" { 197 | // Return the value it has been set to. 198 | return _label 199 | } else if tileType == "url-tile" && _label == "" { 200 | // It hasn't been set. A url-tile (share path) MUST include a label, otherwise it will not be displayed. 201 | if let unwrappedCfurlString = cfurlString { 202 | let path = NSString(string: unwrappedCfurlString) 203 | // Remove any extension and extract the last part of the path (e.g. Shared). 204 | let extractedLabel = path.lastPathComponent 205 | return extractedLabel 206 | } 207 | } 208 | // It's not a url/share. 209 | return nil 210 | } 211 | set { 212 | // If newValue is not nil. 213 | if let unwrappedNewValue = newValue { 214 | // Store the new value in _displayAs. 215 | _label = unwrappedNewValue 216 | } else { 217 | // Set _label to "" to reflect no preference. 218 | _label = "" 219 | } 220 | } 221 | } 222 | 223 | // If removable is set in make the dock item removable. Note: this only applies to plist output, profiles do not support opt. 224 | var removable: Bool = false 225 | 226 | // Note: making an argument optional will allow input to be nil. 227 | init(cfurlString: String, arrangement: Int? = nil, showAs: Int? = nil, displayAs: Int? = nil, label: String? = nil, removable: Bool? = false) { 228 | self.cfurlString = cfurlString 229 | } 230 | 231 | func generateDockItemXML() -> [String: AnyObject] { 232 | 233 | /* 234 | let appStructure = ["tile-type":tileType!, 235 | "tile-data": 236 | "file-data": 237 | ["_CFURLString":cfurlString!, 238 | "_CFURLStringType":cfurlStringType! 239 | ] 240 | ] 241 | ] 242 | 243 | let shareStructure = ["tile-type":tileType!, 244 | "tile-data": 245 | ["label":label!, 246 | "url": 247 | ["_CFURLString":cfurlString!, 248 | "_CFURLStringType":cfurlStringType! 249 | ] 250 | ] 251 | ] 252 | 253 | 254 | let directoryStructure = ["tile-type":tileType!, 255 | "tile-data": 256 | ["label":label!, 257 | "home directory relative":homeDirectoryRelative!, 258 | "arrangement":arrangement!, 259 | "displayas":displayAs!, 260 | "showas":showAs! 261 | ] 262 | ] 263 | */ 264 | 265 | var dockItemXML = [String: AnyObject]() 266 | var tileData = [String: AnyObject]() 267 | var fileData = [String: AnyObject]() 268 | 269 | dockItemXML["tile-type"] = tileType 270 | 271 | // ["tile-data"] 272 | if let unwrappedhomeDirectoryRelative = homeDirectoryRelative { 273 | tileData["home directory relative"] = unwrappedhomeDirectoryRelative 274 | } 275 | if let unwrappedArrangement = arrangement { 276 | tileData["arrangement"] = unwrappedArrangement 277 | } 278 | if let unwrappedDisplayAs = displayAs { 279 | tileData["displayas"] = unwrappedDisplayAs 280 | } 281 | if let unwrappedShowAs = showAs { 282 | tileData["showas"] = unwrappedShowAs 283 | } 284 | if let unwrappedLabel = label { 285 | tileData["label"] = unwrappedLabel 286 | } 287 | 288 | // ["file-data"]/["url"] 289 | if let unwrappedCFURLString = cfurlString { 290 | fileData["_CFURLString"] = unwrappedCFURLString 291 | } 292 | if let unwrappedCFURLStringType = cfurlStringType { 293 | fileData["_CFURLStringType"] = unwrappedCFURLStringType 294 | } 295 | 296 | 297 | // If fileData is not empty insert ["file-data"]/["url"] into ["tile-data"]. 298 | if !fileData.isEmpty { 299 | if let tileType = dockItemXML["tile-type"] as? String { 300 | // If dock item is a URL use "url" as key instead of "file-data" 301 | if tileType == "url-tile" { 302 | tileData["url"] = fileData 303 | } else { 304 | tileData["file-data"] = fileData 305 | } 306 | } 307 | } 308 | 309 | dockItemXML["tile-data"] = tileData 310 | 311 | return dockItemXML 312 | } 313 | 314 | 315 | func convertAppCFURLStringType15ToCFURLStringType0(cfurlStringType15: String) -> String? { 316 | // Convert file:///Applications/Safari.app/ to /Applications/Safari.app/. 317 | let pathWithoutScheme = cfurlStringType15.stringByReplacingOccurrencesOfString("file://", withString: "") 318 | // Convert /Applications/Safari.app/ to /Applications/Safari.app. 319 | let cfurlStringType0 = NSURL(fileURLWithPath: pathWithoutScheme).path 320 | return cfurlStringType0 321 | } 322 | 323 | } 324 | 325 | 326 | 327 | 328 | class Dock { 329 | 330 | // Becomes dockmaster.lowercaseSpacelessDisplayName. Profiles with the same identifier are overwritten. 331 | var payloadIdentifier: String { 332 | get { 333 | let lowercaseSpacelessDisplayName = payloadDisplayName.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "") 334 | return lowercaseSpacelessDisplayName 335 | } 336 | } 337 | // Defines whether the profile can be removed. 338 | // With PayloadRemovalDisallowed set to true, profiles installed manually can only be removed using administrative authority. However if the profile is installed by an MDM, only the MDM can remove the profile (applies to 10.10 and later). 339 | var payloadRemovalDisallowed: Bool = true 340 | // Determines if this profile be applied to all users (System) or just the current user (User)? 341 | var payloadScope: String 342 | // Currently, a profile payload type can only be Configuration. 343 | let payloadType = "Configuration" 344 | // Generates a random Universal Unique Identifier. 345 | let payloadUUID = NSUUID().UUIDString 346 | // The version number of the profile format. Currently, this should be 1. 347 | let payloadVersion = 1 348 | // Pretty name displayed to users (e.g. Student Dock). 349 | var payloadDisplayName: String 350 | // Organization name display to users (e.g. Error-free IT). 351 | var payloadOrganization: String? 352 | // Description of the profile (e.g. "Music Lab dock profile"). 353 | var payloadDescription: String? 354 | 355 | let dockPayloadType = "com.apple.dock" 356 | // Currently, all dock payloads are version 1, but Apple may release a new payload version to support additional features. 357 | let dockPayloadVersion = 1 358 | // Becomes lowercaseSpacelessDisplayName. 359 | var dockPayloadIdentifier: String { 360 | get { 361 | return "dockmaster.\(payloadIdentifier)" 362 | } 363 | } 364 | // Whether payload should be acted upon. 365 | let dockPayloadEnabled = true 366 | // Generates a random Universal Unique Identifier. 367 | let dockPayloadUUID = NSUUID().UUIDString 368 | // Payload display name presented to the user during profile install. 369 | let dockPayloadDisplayName = "Dock" 370 | // Prevents the dock from being modified. 371 | var dockContentsImmutable: Bool 372 | // Removes any existing dock items before adding the dock items in the profile. 373 | var dockStaticOnly: Bool 374 | // Arrays of dock applications. 375 | var dockStaticApps = [DockItem]() 376 | var dockPersistentApps = [DockItem]() 377 | // Arrays of dock others (directories, shares and bookmarks). 378 | var dockStaticOthers = [DockItem]() 379 | var dockPersistentOthers = [DockItem]() 380 | // Adds the user's network home folder to the dock. Note: This will add a duplicate if the directory services plugin is also set to add the network home folder to the dock. 381 | var dockAddNetworkHome: Bool? 382 | // Sets the tile size (maximum icon size). The value can be anywhere between 1 and 256, (larger number = larger tiles). 68 is OS X's default value. 383 | var dockTileSize: Int? 384 | var dockTileSizeImmutable: Bool? 385 | // Enable magnification when hovering over dock items. OS X disables this feature by default. 386 | var dockMagnification: Bool? 387 | var dockMagnificationImmutable: Bool? 388 | // Sets the level of magnification when hovering over dock items. The value can be anywhere between 1 and 256, (larger number = larger magnification). 389 | var dockMagnificationSize: Int? 390 | var dockMagnificationSizeImmutable: Bool? 391 | // Sets the position of the dock. It can either be left, bottom (default) or right. 392 | var dockPosition: String? 393 | var dockPositionImmutable: Bool? 394 | // Sets the dock minimize effect, it can either be genie (default) or scale. 395 | var dockMinimizeEffect: String? 396 | var dockMinimizeEffectImmutable: Bool? 397 | // Whether applications animate (bounce) on open. 398 | var dockAnimateAppLaunch: Bool? 399 | var dockAnimateAppLaunchImmutable: Bool? 400 | // Whether the dock hides and only appears on hover. 401 | var dockAutoHide: Bool? 402 | // Displays a light or black dot (depending on OS X version) to indicate the application is running. OS X enables this feature by default. 403 | var dockShowProcessIndicators: Bool? 404 | var dockShowProcessIndicatorsImmutable: Bool? 405 | // Sets application windows to minimize into their respective application icon. OS X disables this feature by default. 406 | var dockMinimizeIntoApp: Bool? 407 | var dockMinimizeIntoAppImmutable: Bool? 408 | 409 | // Packages generated apply to existing user accounts (true) or only new user accounts (false). 410 | var packageAppliesToExistingUsers = true 411 | // Version number of package. 412 | var packageVersion = "1.0" 413 | 414 | init(payloadScope: String = "System", payloadDisplayName: String = "Custom Dock", dockContentsImmutable: Bool = false, dockStaticOnly: Bool = false) { 415 | 416 | self.payloadScope = payloadScope 417 | self.payloadDisplayName = payloadDisplayName 418 | 419 | self.dockContentsImmutable = dockContentsImmutable 420 | self.dockStaticOnly = dockStaticOnly 421 | 422 | } 423 | 424 | // Add a new dock item to dock array. 425 | func addNewDockItem(dockItem: DockItem) { 426 | if dockItem.tileType == "file-tile" && !dockItem._cfurlString.hasSuffix(".webloc") { 427 | if dockItem.removable { 428 | self.dockPersistentApps.append(dockItem) 429 | } else { 430 | self.dockStaticApps.append(dockItem) 431 | } 432 | } else { 433 | if dockItem.removable { 434 | self.dockPersistentOthers.append(dockItem) 435 | } else { 436 | self.dockStaticOthers.append(dockItem) 437 | } 438 | } 439 | } 440 | 441 | func generateUniversalXML() -> [String: AnyObject] { 442 | var universalXML = [String: AnyObject]() 443 | 444 | universalXML["contents-immutable"] = dockContentsImmutable 445 | 446 | if let unwrappedDockAddNetworkHome = dockAddNetworkHome { 447 | if unwrappedDockAddNetworkHome { 448 | universalXML["MCXDockSpecialFolders"] = ["AddDockMCXOriginalNetworkHomeFolder"] 449 | } 450 | } 451 | 452 | if let unwrappedDockTileSize = dockTileSize { 453 | universalXML["tilesize"] = unwrappedDockTileSize 454 | } 455 | if let unwrappedDockTileSizeImmutable = dockTileSizeImmutable { 456 | universalXML["size-immutable"] = unwrappedDockTileSizeImmutable 457 | } 458 | 459 | if let unwrappedDockMagnification = dockMagnification { 460 | universalXML["magnification"] = unwrappedDockMagnification 461 | } 462 | if let unwrappedDockMagnificationImmutable = dockMagnificationImmutable { 463 | universalXML["magnify-immutable"] = unwrappedDockMagnificationImmutable 464 | } 465 | 466 | if let unwrappedDockMagnificationSize = dockMagnificationSize { 467 | universalXML["largesize"] = unwrappedDockMagnificationSize 468 | } 469 | if let unwrappedDockMagnificationSizeImmutable = dockMagnificationSizeImmutable { 470 | universalXML["magsize-immutable"] = unwrappedDockMagnificationSizeImmutable 471 | } 472 | 473 | if let unwrappedDockPosition = dockPosition { 474 | universalXML["orientation"] = unwrappedDockPosition 475 | } 476 | if let unwrappedDockPositionImmutable = dockPositionImmutable { 477 | universalXML["position-immutable"] = unwrappedDockPositionImmutable 478 | } 479 | 480 | if let unwrappedDockMinimizeEffect = dockMinimizeEffect { 481 | universalXML["mineffect"] = unwrappedDockMinimizeEffect 482 | } 483 | if let unwrappedDockMinimizeEffectImmutable = dockMinimizeEffectImmutable { 484 | universalXML["mineffect-immutable"] = unwrappedDockMinimizeEffectImmutable 485 | } 486 | 487 | if let unwrappedDockAnimateAppLaunch = dockAnimateAppLaunch { 488 | universalXML["launchanim"] = unwrappedDockAnimateAppLaunch 489 | } 490 | if let unwrappedDockAnimateAppLaunchImmutable = dockAnimateAppLaunchImmutable { 491 | universalXML["launchanim-immutable"] = unwrappedDockAnimateAppLaunchImmutable 492 | } 493 | 494 | if let unwrappedDockAutoHide = dockAutoHide { 495 | universalXML["autohide"] = unwrappedDockAutoHide 496 | } 497 | 498 | if let unwrappedDockShowProcessIndicators = dockShowProcessIndicators { 499 | universalXML["show-process-indicators"] = unwrappedDockShowProcessIndicators 500 | } 501 | if let unwrappedDockShowProcessIndicatorsImmutable = dockShowProcessIndicatorsImmutable { 502 | universalXML["show-process-indicators-immutable"] = unwrappedDockShowProcessIndicatorsImmutable 503 | } 504 | 505 | if let unwrappedDockMinimizeIntoApp = dockMinimizeIntoApp { 506 | universalXML["minimize-to-application"] = unwrappedDockMinimizeIntoApp 507 | } 508 | if let unwrappedDockMinimizeIntoAppImmutable = dockMinimizeIntoAppImmutable { 509 | universalXML["minimize-to-application-immutable"] = unwrappedDockMinimizeIntoAppImmutable 510 | } 511 | 512 | // If dockStaticApps is not empty. 513 | if !dockStaticApps.isEmpty { 514 | universalXML["static-apps"] = generateCombinedDockItemXML(dockStaticApps) 515 | } 516 | 517 | // If dockStaticOthers is not empty. 518 | if !dockStaticOthers.isEmpty { 519 | universalXML["static-others"] = generateCombinedDockItemXML(dockStaticOthers) 520 | } 521 | 522 | 523 | return universalXML 524 | 525 | } 526 | 527 | func generateProfileXML() -> [String: AnyObject] { 528 | 529 | var profileXML = [String: AnyObject]() 530 | var dockPayloadContent = generateUniversalXML() 531 | 532 | profileXML["PayloadIdentifier"] = payloadIdentifier 533 | profileXML["PayloadRemovalDisallowed"] = payloadRemovalDisallowed 534 | profileXML["PayloadScope"] = payloadScope 535 | profileXML["PayloadType"] = payloadType 536 | profileXML["PayloadUUID"] = payloadUUID 537 | profileXML["PayloadVersion"] = payloadVersion 538 | profileXML["PayloadDisplayName"] = payloadDisplayName 539 | 540 | if let unwrappedPayloadDescription = payloadDescription { 541 | profileXML["PayloadDescription"] = unwrappedPayloadDescription 542 | } 543 | 544 | if let unwrappedPayloadOrganization = payloadOrganization { 545 | profileXML["PayloadOrganization"] = unwrappedPayloadOrganization 546 | } 547 | 548 | dockPayloadContent["PayloadType"] = dockPayloadType 549 | dockPayloadContent["PayloadVersion"] = dockPayloadVersion 550 | dockPayloadContent["PayloadIdentifier"] = dockPayloadIdentifier 551 | dockPayloadContent["PayloadEnabled"] = dockPayloadEnabled 552 | dockPayloadContent["PayloadUUID"] = dockPayloadUUID 553 | dockPayloadContent["PayloadDisplayName"] = dockPayloadDisplayName 554 | dockPayloadContent["static-only"] = dockStaticOnly 555 | 556 | let dockPayloadContentArray: Array = [dockPayloadContent] 557 | profileXML["PayloadContent"] = dockPayloadContentArray 558 | 559 | return profileXML 560 | 561 | } 562 | 563 | func generatePlistXML() -> [String: AnyObject] { 564 | 565 | var plistXML = generateUniversalXML() 566 | 567 | // If dockPersistentApps is not empty. 568 | if !dockPersistentApps.isEmpty { 569 | plistXML["persistent-apps"] = generateCombinedDockItemXML(dockPersistentApps) 570 | } 571 | 572 | // If dockPersistentOthers is not empty. 573 | if !dockPersistentOthers.isEmpty { 574 | plistXML["persistent-others"] = generateCombinedDockItemXML(dockPersistentOthers) 575 | } 576 | 577 | plistXML["version"] = 1 578 | 579 | return plistXML 580 | 581 | } 582 | 583 | private func generateCombinedDockItemXML(dockItems: [DockItem]) -> [[String: AnyObject]] { 584 | 585 | var combinedDockItemsXML = [[String: AnyObject]]() 586 | 587 | for dockItem in dockItems { 588 | combinedDockItemsXML.append(dockItem.generateDockItemXML()) 589 | } 590 | 591 | return combinedDockItemsXML 592 | 593 | } 594 | 595 | // Function to load a dock template from file, into a Dock object. 596 | func loadDockTemplate(templateDockFile: String) -> Dock { 597 | 598 | let templateDock = Dock() 599 | 600 | if let loadedPlist = FileOperation().readDictionaryFromFile(templateDockFile) { 601 | 602 | if let displayName = loadedPlist["display_name"] as? String { 603 | templateDock.payloadDisplayName = displayName 604 | } 605 | 606 | if let organization = loadedPlist["organization"] as? String { 607 | templateDock.payloadOrganization = organization 608 | } 609 | 610 | if let description = loadedPlist["description"] as? String { 611 | templateDock.payloadDescription = description 612 | } 613 | 614 | if let scope = loadedPlist["scope"] as? String { 615 | templateDock.payloadScope = scope 616 | } 617 | 618 | if let contentsImmutable = loadedPlist["contents_immutable"] as? Bool { 619 | templateDock.dockContentsImmutable = contentsImmutable 620 | } 621 | 622 | if let mergeWithExistingDock = loadedPlist["merge_with_existing_dock"] as? Bool { 623 | let staticOnly = !mergeWithExistingDock 624 | templateDock.dockStaticOnly = staticOnly 625 | } 626 | 627 | if let addNetworkHome = loadedPlist["add_network_home"] as? Bool { 628 | templateDock.dockAddNetworkHome = addNetworkHome 629 | } 630 | 631 | if let tileSize = loadedPlist["tile_size"] as? Int { 632 | templateDock.dockTileSize = tileSize 633 | } 634 | if let tileSizeImmutable = loadedPlist["tile_size_immutable"] as? Bool { 635 | templateDock.dockTileSizeImmutable = tileSizeImmutable 636 | } 637 | 638 | if let magnification = loadedPlist["magnification"] as? Bool { 639 | templateDock.dockMagnification = magnification 640 | } 641 | if let magnificationImmutable = loadedPlist["magnification_immutable"] as? Bool { 642 | templateDock.dockMagnificationImmutable = magnificationImmutable 643 | } 644 | 645 | if let magnificationSize = loadedPlist["magnification_size"] as? Int { 646 | templateDock.dockMagnificationSize = magnificationSize 647 | } 648 | if let magnificationSizeImmutable = loadedPlist["magnification_size_immutable"] as? Bool { 649 | templateDock.dockMagnificationSizeImmutable = magnificationSizeImmutable 650 | } 651 | 652 | if let position = loadedPlist["position"] as? String { 653 | templateDock.dockPosition = position 654 | } 655 | if let positionImmutable = loadedPlist["position_immutable"] as? Bool { 656 | templateDock.dockPositionImmutable = positionImmutable 657 | } 658 | 659 | if let minimizeEffect = loadedPlist["minimize_effect"] as? String { 660 | templateDock.dockMinimizeEffect = minimizeEffect 661 | } 662 | if let minimizeEffectImmutable = loadedPlist["minimize_effect_immutable"] as? Bool { 663 | templateDock.dockMinimizeEffectImmutable = minimizeEffectImmutable 664 | } 665 | 666 | if let animateAppLaunch = loadedPlist["animate_app_launch"] as? Bool { 667 | templateDock.dockAnimateAppLaunch = animateAppLaunch 668 | } 669 | if let animateAppLaunchImmutable = loadedPlist["animate_app_launch_immutable"] as? Bool { 670 | templateDock.dockAnimateAppLaunchImmutable = animateAppLaunchImmutable 671 | } 672 | 673 | if let autoHide = loadedPlist["auto_hide"] as? Bool { 674 | templateDock.dockAutoHide = autoHide 675 | } 676 | 677 | if let showProcessIndicators = loadedPlist["show_process_indicators"] as? Bool { 678 | templateDock.dockShowProcessIndicators = showProcessIndicators 679 | } 680 | if let showProcessIndicatorsImmutable = loadedPlist["show_process_indicators_immutable"] as? Bool { 681 | templateDock.dockShowProcessIndicatorsImmutable = showProcessIndicatorsImmutable 682 | } 683 | 684 | if let minimizeIntoApp = loadedPlist["minimize_into_app"] as? Bool { 685 | templateDock.dockMinimizeIntoApp = minimizeIntoApp 686 | } 687 | if let minimizeIntoAppImmutable = loadedPlist["minimize_into_app_immutable"] as? Bool { 688 | templateDock.dockMinimizeIntoAppImmutable = minimizeIntoAppImmutable 689 | } 690 | 691 | if let applications = loadedPlist["applications"] { 692 | for application in applications as! NSArray { 693 | 694 | if let cfurlString = application["cfurl_string"] as? String { 695 | let dockItem = DockItem(cfurlString: cfurlString) 696 | dockItem.removable = application["removable"] as? Bool ?? false 697 | 698 | templateDock.addNewDockItem(dockItem) 699 | } 700 | 701 | } 702 | } 703 | 704 | if let others = loadedPlist["others"] { 705 | for other in others as! NSArray { 706 | 707 | if let cfurlString = other["cfurl_string"] as? String { 708 | let dockItem = DockItem(cfurlString: cfurlString) 709 | 710 | dockItem.arrangement = other["arrangement"] as? Int ?? nil 711 | dockItem.showAs = other["show_as"] as? Int ?? nil 712 | dockItem.displayAs = other["display_as"] as? Int ?? nil 713 | dockItem.label = other["label"] as? String ?? nil 714 | dockItem.removable = other["removable"] as? Bool ?? false 715 | 716 | templateDock.addNewDockItem(dockItem) 717 | } 718 | 719 | } 720 | } 721 | 722 | if let packageAppliesToExistingUsers = loadedPlist["package_applies_to_existing_users"] as? Bool { 723 | templateDock.packageAppliesToExistingUsers = packageAppliesToExistingUsers 724 | } 725 | if let packageVersion = loadedPlist["package_version"] as? String { 726 | templateDock.packageVersion = packageVersion 727 | } 728 | 729 | } 730 | 731 | return templateDock 732 | } 733 | 734 | } --------------------------------------------------------------------------------