Module: Util

Included in:
Bunch, BunchURLGenerator
Defined in:
lib/bunch/url_generator.rb

Overview

misc utils

Instance Method Summary collapse

Instance Method Details

#bundle_id(app) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bunch/url_generator.rb', line 16

def bundle_id(app)
  shortname = app.sub(/\.app$/, '')
  app_dirs = [
    '/Applications',
    '/Applications/Setapp',
    '/Applications/Utilities',
    '~/Applications',
    '/Developer/Applications',
    '/System/Applications'
  ]
  only_in = app_dirs.map { |dir| "-onlyin #{dir}" }.join(' ')
  apps = `mdfind #{only_in} 'kMDItemKind==Application'`

  return false if !apps || apps.strip.empty?

  foundapps = apps.split(/\n/).select! { |line| line.chomp =~ /#{shortname}\.app$/i }

  return false if foundapps.empty?

  foundapp = foundapps[0]

  if foundapp
    `mdls -name kMDItemCFBundleIdentifier -r "#{foundapp}"`.chomp
  else
    # warn "Could not locate bundle id for #{shortname}, using provided app name"
    app
  end
end