Skip to content

Commit 486e323

Browse files
authored
Merge pull request #4 from fubarhouse/issue-3
PR for #3
2 parents 5b4e98a + f14e03d commit 486e323

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Install [Dockutil](https://github.com/kcrawford/dockutil) and remove, add and an
1010

1111
## Role Variables
1212

13+
### Removal of dock items
14+
1315
Dock items to remove:
1416

1517
````
@@ -32,12 +34,17 @@ dockitems_disabled:
3234
- Terminal
3335
````
3436

35-
Or, if you want to remove all dock items, use:
36-
37+
#### Remove all: Preferred method
3738
```
39+
dockitems_remove_all: true
40+
```
41+
#### Remove all: Alternative method:
42+
````
3843
dockitems_disabled:
3944
- all
40-
```
45+
````
46+
47+
### Adding dock items
4148

4249
Dock items to add, including name, path and weight/position:
4350

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# To manage dock items.
77
#
88

9+
dockitems_remove_all: false
10+
911
dockitems_disabled:
1012
- Launchpad
1113
- Mail

tasks/main.yml

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,61 @@
33
- name: Dockutil | Ensure installed.
44
homebrew:
55
name: "dockutil"
6-
state: present
6+
state: installed
77

8-
- name: Dockutil | Remove all unwanted dock items
9-
shell: dockutil --remove "{{ item }}"
10-
ignore_errors: true
8+
- name: Dockutil | Get information on items to remove
9+
shell: "dockutil --find '{{ item }}'"
10+
register: dockutil_removeditems
1111
with_items: "{{ dockitems_disabled }}"
12-
when: "{{ dockitems_disabled | length > 0 }}"
12+
changed_when: false
13+
failed_when: false
14+
when: dockitems_remove_all|bool == false
15+
16+
- name: Dockutil | Remove all dock items
17+
shell: "dockutil --remove all --no-restart"
18+
register: removed_items_task
19+
when: dockitems_remove_all|bool == true
20+
21+
- name: Dockutil | Remove all unwanted dock items
22+
shell: "dockutil --remove '{{ item.item }}' --no-restart"
23+
register: removed_items_task
24+
with_items: "{{ dockutil_removeditems.results }}"
25+
when:
26+
- dockitems_remove_all|bool == false
27+
- '"{{ item.item }} was found in persistent-apps" in item.stdout'
28+
29+
- name: Dockutil | Get information on configured setup
30+
shell: "dockutil --find '{{ item.name }}'"
31+
register: dockutil_newdata
32+
with_items: "{{ dockitems_enabled }}"
33+
changed_when: false
34+
failed_when: false
1335

1436
- name: Dockutil | Adding items
15-
shell: dockutil --find "{{ item.name }}" || dockutil --add "{{ item.path }}"
37+
shell: "dockutil --add '{{ item.item.path }}' --position {{ item.item.pos }} --no-restart"
38+
register: added_items_task
39+
with_items: "{{ dockutil_newdata.results }}"
40+
when: '"{{ item.item.name }} was not found in" in item.stdout'
41+
42+
- name: Dockutil | Get information on current setup
43+
shell: "dockutil --find '{{ item.name }}'"
44+
register: dockutil_currdata
1645
with_items: "{{ dockitems_enabled }}"
17-
when: "{{ dockitems_enabled | length > 0 }}"
46+
changed_when: false
47+
failed_when: false
1848

1949
- name: Dockutil | Moving items
20-
shell: dockutil --move "{{ item.name }}" --position "{{ item.pos }}"
21-
with_items: "{{ dockitems_enabled }}"
22-
when: "{{ dockitems_enabled | length > 0 }}"
50+
shell: "dockutil --move '{{ item.item.name }}' --position {{ item.item.pos }} --no-restart"
51+
register: moved_items_task
52+
with_items: "{{ dockutil_currdata.results }}"
53+
when:
54+
- '"{{ item.item.name }} was found in persistent-apps at slot {{ item.item.pos }} in" not in item.stdout'
55+
- '"{{ item.item.name }} was not found" not in item.stdout'
56+
57+
- name: Dockutil | Restart Dock
58+
shell: "/usr/bin/killall Dock"
59+
changed_when: false
60+
when: >
61+
removed_items_task.changed|bool == true or
62+
moved_items_task.changed|bool == true or
63+
added_items_task.changed|bool == true

0 commit comments

Comments
 (0)