-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved capi link indexing to Ruby; fixed installation order
- Loading branch information
Davis W. Frank
authored and
pivotal
committed
Jul 24, 2018
1 parent
4c39a61
commit bdd1d36
Showing
6 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'plist' | ||
gem 'rainbow' | ||
gem 'thor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
plist (3.4.0) | ||
rainbow (3.0.0) | ||
thor (0.20.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
plist | ||
rainbow | ||
thor | ||
|
||
BUNDLED WITH | ||
1.16.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'plist' | ||
|
||
class Bookmarks | ||
def initialize(path) | ||
@path = path | ||
@plist_hash = Plist.parse_xml(`plutil -convert xml1 -o - #{@path}`) | ||
end | ||
|
||
def folder_names | ||
@plist_hash['Children'].collect {|b| b['Title']} | ||
end | ||
|
||
def reset_capi_folder | ||
@capi_folder_index = if folder_names.include? 'CAPI' | ||
capi_folder_index = folder_names.find_index {|f| f == 'CAPI'} | ||
capi_folder = @plist_hash['Children'][capi_folder_index] | ||
capi_folder['Children'] = [] | ||
capi_folder_index | ||
else | ||
@plist_hash['Children'].push( | ||
{ 'Title' => 'CAPI', | ||
'WebBookmarkType' => 'WebBookmarkTypeList', | ||
'Children' => [] | ||
}) | ||
@plist_hash['Children'].count - 1 | ||
end | ||
end | ||
|
||
def insert_links_into_capi_folder(new_links) | ||
capi_folder = @plist_hash['Children'][@capi_folder_index] | ||
capi_folder_links = capi_folder['Children'] | ||
|
||
new_links.each do |name, url| | ||
capi_folder_links.push(bookmark_hash_for(name, url)) | ||
end | ||
end | ||
|
||
def write_file | ||
File.open(@path, 'w') {|f| f.write @plist_hash.to_plist} | ||
end | ||
|
||
private | ||
|
||
def bookmark_hash_for(name, url) | ||
{'ReadingListNonSync' => | ||
{'neverFetchMetadata' => false}, | ||
'URIDictionary' => | ||
{'title' => name}, | ||
'URLString' => url, | ||
'WebBookmarkType' => 'WebBookmarkTypeLeaf', | ||
'previewText' => '', | ||
'previewTextIsUserDefined' => true} | ||
end | ||
end | ||
|
||
bookmarks = Bookmarks.new(File.join('/Users', 'pivotal', 'Library', 'Safari', 'Bookmarks.plist')) | ||
bookmarks.reset_capi_folder | ||
bookmarks.insert_links_into_capi_folder( | ||
{ | ||
'CAPI Trello' => 'http://board.capi.land', | ||
'Chris' => 'http://chris.capi.land', | ||
'CI' => 'https://ci.capi.land', | ||
'Elena' =>'http://elena.capi.land', | ||
'Greg' => 'http://greg.capi.land', | ||
'Mike' => 'http://mike.capi.land', | ||
'Tim' => 'http://tim.capi.land', | ||
'Video' =>'http://video.capi.land' | ||
} | ||
) | ||
bookmarks.write_file | ||
|
||
# Open Safari to re-read new links, then close | ||
`open -a "Safari"` | ||
sleep 2 | ||
`osascript -e 'quit app "Safari"'` |
This file was deleted.
Oops, something went wrong.