Skip to content

Commit 559ea3d

Browse files
committedJan 11, 2023
Append item to search online at bottom of results
1 parent ab6011f commit 559ea3d

File tree

6 files changed

+342
-389
lines changed

6 files changed

+342
-389
lines changed
 

‎README.md

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ List File Stream contents from Google Drive
44

55
<a href='https://alfred.app/workflows/alfredapp/google-drive'>⤓ Install on the Alfred Gallery</a>
66

7-
> On Alfred 4 use <a href='https://github.com/alfredapp/google-drive-workflow/releases/download/2022.12/Google.Drive.alfredworkflow'>alternative link</a>
8-
97
## Usage
108

119
Search the contents of your Google Drive via the Search Keyword (default: `gd`) or Folder Search Keyword (default: `gdf`). [Fallback Searches](https://www.alfredapp.com/help/features/default-results/fallback-searches/) are included.
Loading

‎Workflow/finder_copy

-21
This file was deleted.

‎Workflow/finder_move

-21
This file was deleted.

‎Workflow/gd

+35-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ require 'json'
55
require 'sqlite3'
66

77
Dir_only = ARGV[0] == 'dir_only' ? 'isdir = 1 AND' : ''
8-
Query = ARGV[1].split(' ').map { |w| "%#{w.unicode_normalize}%" }
8+
Suggest_website = ARGV[1] == 'suggest_website'
9+
Typed_query = ARGV[2]
10+
Query = Typed_query.split(' ').map { |w| "%#{w.unicode_normalize}%" }
911
Limit = ENV['result_limit'].to_i <= 0 ? 50 : ENV['result_limit'].to_i
1012
Tmp_file = File.join(ENV['alfred_workflow_cache'], 'tmp.db')
1113
Cache_file = File.join(ENV['alfred_workflow_cache'], 'cache.db')
@@ -16,34 +18,57 @@ unless File.exist?(Cache_file)
1618
require 'open3'
1719

1820
if Open3.capture2('ps', 'A').first.split("\n").any? { |l| l.match(/ruby.*Alfred.*rebuild_cache/) }
19-
puts({ items: [{ title: 'Cache is being built…', subtitle: 'Please be patient. Depending on how many files you have, it can take a while.', 'valid': false }] }.to_json)
21+
puts({ items: [{
22+
title: 'Cache is being built…',
23+
subtitle: 'Please be patient. Depending on how many files you have, it can take a while.',
24+
'valid': false
25+
}] }.to_json)
26+
2027
exit 0
2128
end
2229

23-
puts({ items: [{ title: 'Build cache', subtitle: 'It will take a few minutes to finish, depending on how many files you have.', 'arg': 'build_cache' }] }.to_json)
30+
puts({ items: [{
31+
variables: { build_cache: true },
32+
title: 'Build cache',
33+
subtitle: 'It will take a few minutes to finish, depending on how many files you have.',
34+
'arg': 'build_cache'
35+
}] }.to_json)
36+
2437
exit 0
2538
end
2639

2740
# Filter paths
2841
db = SQLite3::Database.new(Cache_file)
2942
Results = db.execute("SELECT fullpath FROM main WHERE #{Dir_only} #{Array.new(Query.length, 'basename LIKE ?').join(' AND ')} ORDER BY accesstime DESC LIMIT ?;", Query, Limit).flatten
3043

31-
Script_filter_items = Results.each_with_object([]) { |path, array|
44+
Init_script_filter_items = Results.each_with_object([]) { |path, array|
3245
short_path = path.sub(%r{^/Users/.+?/}, '~/').sub(%r{^~/Library/CloudStorage/}, '')
46+
basename = File.basename(path)
3347

3448
array.push(
3549
uid: path,
3650
type: 'file',
37-
title: File.basename(path),
51+
title: basename,
3852
subtitle: short_path,
3953
icon: { path: path, type: 'fileicon' },
40-
arg: path
54+
arg: path,
55+
mods: {
56+
opt: { variables: { reveal_in_finder: true }, subtitle: 'Reveal in Finder' },
57+
shift: { variables: { search_website: true }, subtitle: 'Search on Google Drive’s website', arg: basename }
58+
}
4159
)
4260
}
4361

44-
if Script_filter_items.empty?
45-
puts({ items: [{ title: 'Nothing found', subtitle: 'Try searching something else' }] }.to_json)
46-
exit 0
47-
end
62+
Script_filter_items = lambda {
63+
return Init_script_filter_items unless Suggest_website
64+
65+
# Append item for website search
66+
return Init_script_filter_items.push({
67+
variables: { search_website: true },
68+
title: "Search “#{Typed_query}” on Google Drive’s website",
69+
icon: { path: 'icon.png' },
70+
arg: Typed_query
71+
})
72+
}.call
4873

4974
puts({ items: Script_filter_items }.to_json)

0 commit comments

Comments
 (0)
Failed to load comments.