├── README.md
├── arf
├── WhatIsARF.txt
├── data
│ └── static.arf
├── dynamic.sh
├── img
│ ├── f1
│ │ ├── Bill.jpg
│ │ ├── Calvin.jpg
│ │ ├── Earth.png
│ │ ├── Hobbes.jpg
│ │ ├── Jupiter.png
│ │ ├── Mars.png
│ │ ├── Mercury.png
│ │ ├── Moon.png
│ │ ├── Neptune.png
│ │ ├── Pluto.png
│ │ ├── Saturn.png
│ │ ├── Sun.png
│ │ ├── Uranus.png
│ │ ├── Venus.png
│ │ └── default.png
│ ├── f2
│ │ ├── cake.png
│ │ └── default.png
│ ├── f3
│ │ ├── Male.png
│ │ └── default.png
│ └── sys
│ │ ├── back.png
│ │ └── error.png
├── lib
│ ├── arf+.sh
│ ├── common.sh
│ └── workflowHandler.sh
├── main.sh
└── scripts
│ ├── actions.sh
│ ├── display.sh
│ └── search.sh
├── icon.png
└── info.plist
/README.md:
--------------------------------------------------------------------------------
1 |
Alfred Reference Framework
2 | ==========================
3 |
4 | Framework for Alfred written in Bash which makes it easy to create workflows to search and look up information without leaving the Alfred interface. This gets around the issue caused by the fact that "Script Filters are the only way to pass feedback to Alfred."
5 |
6 |
28 |
29 |
30 | ## What it does:
31 |
32 |
33 | - As with all Alfred Workflows, the user begins by typing in workflow's keyword, in this case, "arf"
34 |
35 |
36 | - The user then types in his/her query, and results are displayed. Again, part of the standard Alfred Workflow.
37 | 
38 |
39 | Normally at this point, the user will select a result and something outside of Alfred will occur, whether that's bring up a webpage, open/do something in a third-party application, etc. The limitations of the Alfred interface mean that once results for a query are displayed, selection of the results means Alfred is done.
40 |
41 |
- With the Alfred Reference Framework, however, this is not the case. Selection of one of the search results generates a special query which then displays results without having to leave Alfred.
42 |
43 |
44 |
45 |
46 |
47 | Another example of a static ARF workflow is the Alfred Tea Master Workflow, which is the code generalized to make ARF.
48 |
49 | ## Installation
50 | Download the latest release, or clone the repository into an empty workflow using these instructions:
51 |
52 |
53 | - Open up Alfred Preferences
54 |
- Click on the "Workflows" tab.
55 |
- Create a new workflow using the plus button on the bottom left and clicking "Blank Workflow".
56 |
- Name it whatever you want, it will get changed.
57 |
- Click the "+" on the top right. Go to Inputs>Script Filter
58 |
- Click on "Open workflow folder"
59 |
- Using Terminal, cd into this directory
60 |
- Once in the directory, delete everything inside of it, then run (with period): git clone https://github.com/cheniel/alfred-reference-framework.git .
61 |
- You may want to create an alias to make it easy to get to this folder from terminal.
62 |
- If you are looking to push this to your own repo, run: git config remote.origin.url [HTTPS of your repo here]
63 |
64 |
65 |
66 | ## Creating an ARF workflow
67 |
68 | There are two ways to create an ARF workflow: static and dynamic.
69 |
70 | Static is best if you have data which does not change. This mode requires no coding and is just a matter of populating a !-delimited text file. The user's input searches over the names of the data.
71 |
72 | Dynamic is best if you have data that changes over time (for example, tweets containing a certain hashtag), from computer to computer, or any other variable. It requires using the ARF+ library and you have to create your own method for determining what results to display (as opposed to the simple name-search offered in static mode).
73 |
74 | After you've installed ARF and picked which mode you want to use, go to the workflow's entry in the Alfred Preferences and double-click on the script filter module.
75 |
76 | If you've picked static mode, make sure the first line of the script portion of the script module is:
77 | > ./arf/main.sh arf/data/static.arf {query} --static
78 |
79 | If you've picked dynamic mode, make sure the first line of the script portion of the script module is:
80 | > ./arf/main.sh arf/data/static.arf {query}
81 |
82 | Both dynamic and static mode have pre-filled examples for you to take a look at.
83 |
84 | ### Static Mode
85 | To create an ARF workflow in static mode, all that is required is modification of static.arf, which is a '!' delimited plain text file in the "data" folder containing the data searched and displayed.
86 |
87 | Here's an example of what the data looks like for the results shown in the example in this README:
88 |
89 | > Sun!1.9891 × 10^30 kilograms!N/A
90 | > Mercury!0.330 x 10^24 kilograms!1
91 | > Venus!4.87 x 10^24!2
92 | > Earth!5.97 x 10^24 kilograms!3
93 | > ...
94 |
95 | That is the input for the data. Each line corresponds to one potential result, you can have them as anything you'd like, with any number of fields (determined by "!" separation), although there are some characters that you should avoid which are documented in the comments of static.arf. ARF will automatically search over the first field for you (in this case Sun, Mercury, Venus...) to give the results back to the user. When a result is selected, the rest of the information in the line of that result will be displayed. See the example above for clarification. When defining data, make sure that the last entry contains a carriage return at the end (press enter).
96 |
97 | There are five other things you need to define as well, which are and must be the first five lines of the file. These are the "preference lines".
98 | > Planet Name!Mass!Order From Sun
99 | > arf/img/f1/default.png!arf/img/f2/default.png!arf/img/f3/default.png
100 | > no!no!no
101 | > no!no!no
102 | > !!!
103 |
104 | Each line has and must have the same number of "!" as the data. Each field in the preferences correspond to the same field in the data. So, for example, the preferences "Planet Name," "arf/img/f1/default.png," "no," "no," and "" all apply to Sun.
105 |
106 | If you are just looking to make a very basic workflow to look up data, you probably only need to modify the first two lines, and the other three should remain the same. Here's what the preference lines are:
107 |
108 | - The first line contains the field names which correspond to the data types. This is displayed when a result is selected in the subtext.
109 |
- The second line defines the default image displayed for that result. An easy starting point is "icon.png" if you don't have images yet.
110 |
- The third line defines the "valid" attribute. This determines whether the "autocomplete" or "argument" attribute is used when the result is selected.
111 |
- The fourth line defines the "autocomplete" attribute, only used when valid is no. When the result is selected, the autocomplete attribute replaces the user query. In ARF, an autocomplete attribute of "no" simply does nothing when the result is selected.
112 |
- The fifth line defines the "argument" attribute, only used when valid is yes. This passes a query to action.sh, which requires some coding. You could use this to open a webpage, run a script, or do a variety of other things.
113 |
114 |
115 | Official documentation on the attributes defined in the last three lines.
116 |
117 | That's all you need! For more explanation on how to make a ARF workflow in static mode, take a look at static.arf, which is commented with instructions.
118 |
119 | Make sure that you remove all non-data and non-preference lines (including empty lines and comment lines) before production, as it slows down your search.
120 |
121 | ### Dynamic Mode
122 | To create a dynamic ARF workflow, you have to modify the dynamic.sh file using the arf+ library. The arf+ library contains methods that you call from within dynamic.sh.
123 |
124 | ##### Setting preferences
125 | The first thing you must do is set the preferences. At the minimum, this takes 2 method calls, but if you want to customize all the preferences it takes 6. Here is what setting preferences looks like:
126 | > setFieldNames "Name" "Birthday" "Gender"
127 | > ...add optional preference methods here...
128 | > establishPreferences
129 |
130 | The first and third methods in the snippet are the two required calls. setFieldNames corresponds to filling out the first preference line in the .arf file. It also establishes the number of fields as well as initializing the rest of the lines to default values. establishPreferences uses all of the preference method calls to create a temporary .arf file in the user's volatile data folder. You can make the preferences specific to the user's query, however you should never begin adding data until establishPreferences is called.
131 |
132 | The optional preference methods correspond to the other four preference lines. They must be called after setFieldNames and before establishPreferences. Here are the methods:
133 | > setIcons "icon.png" "icon.png" "icon.png"
134 | > setValidity "no" "no" "no"
135 | > setAutocomplete "no" "no" "no"
136 | > setArguments "" "" ""
137 |
138 | Each of these calls should have the same number of arguments as setFieldNames. The specific snippet shown above doesn't actually do anything, as the method calls in the snippet all pass in the default values which have already been set by setFieldNames (e.g. default icons are "icon.png" for all fields, validity is "no", etc.). Read about the attribute types here.
139 |
140 | ##### Adding data
141 | After establishing preferences, you can begin adding data based on the user's query. For your convenience, the user's query is stored in a variable. Here is an example from dynamic.sh which responds to the user's query "cah".
142 |
143 | > if [ "$userInput" == "cah" ]; then
144 | > addData "$userInput" "Calvin" "November 18, 1985" "Male"
145 | > addData "$userInput" "Hobbes" "November 18, 1985" "Male"
146 | > addData "$userInput" "Bill" "July 5, 1958" "Male"
147 | > fi
148 |
149 | After finding that the user's query is "cah", the script adds three results using the arf+ method addData. To use add data, you must call the method with the number of arguments that were passed into setFieldNames plus one. The first argument is always just "$userInput", and the other arguments all correspond to the data in the fields. This code snippet produces an Alfred result as below:
150 |
151 | 
152 |
153 | Here is the result of selecting "Calvin":
154 |
155 | 
156 |
157 | Check out dynamic.sh for another example.
158 |
159 | The very last method call in every dynamic.sh should be the ARF+ method pushData. It doesn't require any methods and just gives the data to Alfred to display.
160 |
161 | ##### Setting a custom error message
162 | If the user inputs a query that produces no results, arf+ will automatically display an error message when pushData is called. The default error message looks like this:
163 |
164 | 
165 |
166 | If you want to set a custom error message, use this method:
167 | > setError "LARGE TEXT" "SUB TEXT"
168 |
169 | To choose what is displayed when no calls to addData are made because of the user's query.
170 |
171 | ### Result-specific Icons
172 | The previous guides for static and dynamic modes show how to set a default icon for a specific field. If you want to generate a custom icon for a specific result in a field, you have to add images to arf/img/fN where N is the number of the field that you want to have a custom icon in.
173 |
174 | Here is an example of custom icons for results in field 1.
175 |
176 | 
177 |
178 | For the icon to display alongside the result, the name of the file must be the same as the name of the result. Nothing else needs to be done. Running ARF on static mode with the sample data, we can see that this works.
179 |
180 | 
181 |
182 | This applies for any and all of the fields that you use. They just have to be in the correct folder (e.g. f1).
183 |
184 | ### Interactivity
185 | Interactivity can be added in either static or dynamic mode. It occurs in the display mode, after a result is selected, as in the image below.
186 |
187 |
188 |
189 | Interactivity in this example refers to the ability to perform a google search on the tea (field 1), view similar types (field 2) and start a timer (field 5).
190 |
191 | There are two kinds of interactions that can occur when a user selects a display item; query replacement and script run. In the example above, field 1 and 5 are script runs and field 2 is a query replacement.
192 |
193 |
194 | - Query Replacement is when the user's argument is modified on selection of a result. This is actually the primary method of navigation in ARF+ and occurs when you select a result or a back button. To enable this, set the field validity to "no" and autocomplete to whatever you want the user's query to be replaced with.
195 |
- Script run is when a script is run on the selection of a result. This could include interactions with some API, opening a webpage, or filesystem modification, etc. To create script run interactivity, set validity to "yes" and the argument to some keyword, such as "openHelpWebpage". When the field is selected with script run, the argument is passed to the actions.sh script to be processed. Just create a conditional checking that the argument is "openHelpWebPage" and run the appropriate script.
196 |
197 |
198 | See guides for static mode and dynamic mode above to see how you can change these attributes based on the field.
199 |
200 | Take a look at the Alfred Tea Master Workflow to see an example of what interactivity is.
201 |
202 |
203 | ## Development
204 | Please feel free to contribute.
205 |
206 | ###Future Additions / Potential Pull Requests
207 |
208 | - Ability to specify searchable fields
209 |
- ARF+ method which enables searching static as well as dynamic data in dynamic mode.
210 |
- Display either recent searches (by saving user input when they select a result) or default searches (similar to in Alfred Tea Master Workflow) before user inputs a query
211 |
- Ability to add interactively add data from Alfred interface (static only)
212 |
213 |
214 | ### Acknowledgements
215 | Bash Workflow Handler by markokaestner for handling XML.
216 |
217 |
218 | ## Examples
219 |
222 | Let me know if you use it to make a workflow and I'll put it here.
223 |
--------------------------------------------------------------------------------
/arf/WhatIsARF.txt:
--------------------------------------------------------------------------------
1 | ARF stands for Alfred Reference Framework
2 | It is the framework used to create this workflow, primarily assisting with the display of information on a result without leaving alfred.
3 |
4 | Here is the github page:
5 | https://github.com/cheniel/alfred-reference-framework
6 |
7 | ARF developers, please do not delete this file.
--------------------------------------------------------------------------------
/arf/data/static.arf:
--------------------------------------------------------------------------------
1 | Planet Name!Mass!Order From Sun
2 | arf/img/f1/default.png!arf/img/f2/default.png!arf/img/f3/default.png
3 | no!no!no
4 | no!no!no
5 | !!!
6 |
7 | !!!!!!! GUIDE TO FIRST FIVE LINES !!!!!!!
8 | !! Line 1 contains the value names (subtext)
9 | !! Line 2 contains the default icons corresponding to those values
10 | !! Line 3 defines the valid attribute (if you don't know, no)
11 | !! Line 4 defines the autocomplete attribute (if you don't know, no)
12 | !! Line 5 defines the argument attribute (if you don't know, leave blank)
13 |
14 | !!!!!!!!!!!!!!!!! NOTES !!!!!!!!!!!!!!!!!
15 | !! <-- Comment using at least two bangs
16 | !! Data is everything after the first four lines that is not a comment
17 | !! Don't use a bang in your values.
18 | !! You can remove everything from GUIDE TO THE FIRST FIVE LINES to DATA (inclusive) in this file once you are done.
19 | !! Only the first field, in this case, the planet names, will be searched.
20 | !! Cannot put ' in data
21 |
22 | !!!!!!!!!!!!!!!!! DATA !!!!!!!!!!!!!!!!!!
23 | Sun!1.9891 × 10^30 kilograms!N/A
24 | Mercury!0.330 x 10^24 kilograms!1
25 | Venus!4.87 x 10^24!2
26 | Earth!5.97 x 10^24 kilograms!3
27 | Moon!0.073 x 10^24 kilograms!3 (combined with Earth)
28 | Mars!0.642 x 10^24 kilograms!4
29 | Jupiter!1898 x 10^24 kilograms!5
30 | Saturn!568 x 10^24 kilograms!6
31 | Uranus!86.8 x 10^24 kilograms!7
32 | Neptune!102 x 10^24 kilograms!8
33 | Pluto!0.0131 x 10^24 kilograms!9
34 | !!!!!!!!!!!!!!!!!! END !!!!!!!!!!!!!!!!!!
--------------------------------------------------------------------------------
/arf/dynamic.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # dynamic.sh
3 | # Part of the Alfred Reference Framework
4 | #
5 | # Modified by __________ for the _________ Alfred Workflow
6 | #
7 | # Description: Used to create results from dynamic data
8 | #
9 | # Part of ARF+, which generate dynamic data to be displayed in Alfred 2.
10 | #
11 | # Parameters:[default static .arf][user input]
12 | #
13 | # Make sure that the script filter has the "--dynamic" option enabled
14 |
15 | # Libaries
16 | . arf/lib/arf+.sh # ARF+ Libary
17 |
18 | # Arguments
19 | defaultARF="$1"
20 | userInput="$2"
21 |
22 | ###############################################################################
23 | # MODIFY BELOW THIS LINE #
24 | ###############################################################################
25 | # Set preferences (analogous to first five lines of static .arf)
26 |
27 | # SET UP FIELD NAMES
28 | # Always begin with setting up field names. All field names must have an
29 | # argument name in this function call, as this function is also the basis of
30 | # how many fields will be used in the file.
31 | setFieldNames "Name" "Birthday" "Gender"
32 |
33 | # SET UP OTHER FOUR PREFERENCES
34 | # These four are optional. Go ahead and delete their calls if you don't want
35 | # to use them. They were defined to their default values when setFieldNames
36 | # was called
37 |
38 | setIcons "icon.png" "arf/img/f2/cake.png" "icon.png" # default: "icon.png" "icon.png" ... "icon.png"
39 | setValidity "no" "no" "no" # default sets all to no
40 | setAutocomplete "no" "no" "no" # default sets all to no
41 | setArguments "" "" "" # default leaves blank
42 |
43 | # Don't remove this. Just call it once you've set your preferences
44 | # and before you begin to add data.
45 | establishPreferences
46 |
47 |
48 | # ADD DATA
49 | # Do this however you like. Here are some examples.
50 | # Base the information you display on the users query,
51 | # when working with ARF+, EVERY CALL to addData WILL APPEAR on the
52 | # Alfred results.
53 | # Always make first argument the user's input.
54 |
55 | # EX. 1: Just add a specified lines if the user inputs a certain query
56 | # try it out by typing "arf cah" in Alfred.
57 | if [ "$userInput" == "cah" ]; then
58 | addData "$userInput" "Calvin" "November 18, 1985" "Male"
59 | addData "$userInput" "Hobbes" "November 18, 1985" "Male"
60 | addData "$userInput" "Bill" "July 5, 1958" "Male"
61 | fi
62 |
63 |
64 | # EX. 2: Retrieve information from elsewhere and parse it
65 | # This example pulls information about the files on ~/Documents
66 | # try it out by typing "arf desk" in Alfred.
67 |
68 | # You could easily modify this so that the user specifies which folder at
69 | # root to look at.
70 |
71 | if [ "$userInput" == "doc" ]; then
72 |
73 | # Pull the information from the desktop
74 | desktopFiles=`ls -l ~/Documents | sed -n '1!p'`
75 |
76 | # For each file (line) in the string
77 | while read -r line; do
78 |
79 | # Get the file name
80 | filename=`echo $line | cut -d ' ' -f9,10,11,12,13,14` # assumes < 6 spaces
81 |
82 | # Get the date it was created
83 | filedate=`echo $line | cut -d ' ' -f6,7,8`
84 |
85 | # Get the file type
86 | filetype=`echo $line | cut -d ' ' -f1` # removes @
87 |
88 | # add Data
89 | addData "$userInput" "$filename" "$filedate" "$filetype"
90 |
91 | # break if numberOfResults >= 20.
92 | # numberOfResults is an arf+ variable that keeps track of the number
93 | # of calls to addData for you.
94 | if [ $numberOfResults -ge 20 ]; then
95 | break
96 | fi
97 |
98 | done <<< "$desktopFiles"
99 | fi
100 |
101 | # Neither of these examples demonstrate any search compatibility.
102 | # Use the user input to define what calls to addData you make.
103 |
104 | # advice and warnings for adding data:
105 | # - single quotes, "<", ">", and other characters that pose problems with XML
106 | # will pose problems in Alfred as well. ARF+ will handle a good amount of
107 | # errors such as these by substituting characters, so using these characters
108 | # could result in unexpected behavior--e.g. colons will be converted
109 | # to dashes.
110 | # - Don't over populate the data. Remember -- Alfred only gives you 20
111 | # reponses per search. That's a good place to cut it adding data to
112 | # reduce runtime.
113 |
114 | ### OPTIONAL CUSTOM ERROR MESSAGE
115 | # set the error message that is displayed
116 | # default is "No results were found" "Try another search"
117 | setError "No results were found" "Try either {arf cah} or {arf doc} to see standard arf+ examples"
118 |
119 | ###############################################################################
120 | # MODIFY ABOVE THIS LINE #
121 | ###############################################################################
122 | # Call search using dynamic.arf. removed because of design change
123 | # echo `./arf/scripts/search.sh "$data" "$userInput"`
124 | pushData
125 |
126 |
--------------------------------------------------------------------------------
/arf/img/f1/Bill.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Bill.jpg
--------------------------------------------------------------------------------
/arf/img/f1/Calvin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Calvin.jpg
--------------------------------------------------------------------------------
/arf/img/f1/Earth.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Earth.png
--------------------------------------------------------------------------------
/arf/img/f1/Hobbes.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Hobbes.jpg
--------------------------------------------------------------------------------
/arf/img/f1/Jupiter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Jupiter.png
--------------------------------------------------------------------------------
/arf/img/f1/Mars.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Mars.png
--------------------------------------------------------------------------------
/arf/img/f1/Mercury.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Mercury.png
--------------------------------------------------------------------------------
/arf/img/f1/Moon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Moon.png
--------------------------------------------------------------------------------
/arf/img/f1/Neptune.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Neptune.png
--------------------------------------------------------------------------------
/arf/img/f1/Pluto.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Pluto.png
--------------------------------------------------------------------------------
/arf/img/f1/Saturn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Saturn.png
--------------------------------------------------------------------------------
/arf/img/f1/Sun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Sun.png
--------------------------------------------------------------------------------
/arf/img/f1/Uranus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Uranus.png
--------------------------------------------------------------------------------
/arf/img/f1/Venus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/Venus.png
--------------------------------------------------------------------------------
/arf/img/f1/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f1/default.png
--------------------------------------------------------------------------------
/arf/img/f2/cake.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f2/cake.png
--------------------------------------------------------------------------------
/arf/img/f2/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f2/default.png
--------------------------------------------------------------------------------
/arf/img/f3/Male.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f3/Male.png
--------------------------------------------------------------------------------
/arf/img/f3/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/f3/default.png
--------------------------------------------------------------------------------
/arf/img/sys/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/sys/back.png
--------------------------------------------------------------------------------
/arf/img/sys/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/arf/img/sys/error.png
--------------------------------------------------------------------------------
/arf/lib/arf+.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # arf+.sh
3 | # Part of the Alfred Reference Framework
4 | #
5 | # Library for dynamic.sh used to create results
6 | # Part of ARF+, which generate dynamic data to be displayed in Alfred 2.
7 | #
8 |
9 | . arf/lib/common.sh
10 |
11 | numberOfFields=0
12 | numberOfResults=0
13 |
14 | prefFilename="preferences.arf"
15 | pref="$DATA_DIRECTORY$prefFilename"
16 |
17 | # Check and creation of volatile data folder for preferences
18 | if [ ! -d "$DATA_DIRECTORY" ]; then
19 | mkdir "$DATA_DIRECTORY"
20 | fi
21 |
22 | # Check and reset of preferences.arf
23 | if [ -f "$pref" ]; then
24 | rm -f "$pref" # deletion of old
25 | fi
26 |
27 | touch "$pref" # create new preference file
28 |
29 | err1="No results were found"
30 | err2="Try another search"
31 |
32 | declare -a names
33 | declare -a icons
34 | declare -a valid
35 | declare -a autocomplete
36 | declare -a argument
37 |
38 | ###############################################################################
39 | # FUNCTIONS #
40 | ###############################################################################
41 |
42 | # first arg should be the users search query
43 | # Add data to be displayed in Alfred
44 | # e.g.
45 | # addData "$userInput" "Calvin" "November 18, 1985" "Male"
46 | addData() {
47 |
48 | # create line. placed before checks for error messages
49 | line=""
50 | for i in "${@:2}"
51 | do
52 | line="$line$i$DELIMITER"
53 | done
54 |
55 | # Check that setFieldNames has been called
56 | if [ $numberOfFields -gt 0 ]; then
57 |
58 | correctNargs=$(($numberOfFields+1))
59 |
60 | # Check that the user provided the right number of arguments
61 | if [ $correctNargs -eq $# ]; then
62 |
63 | # get icon
64 | if [ -f "arf/img/f1/$2.png" ]; then
65 | iconString="arf/img/f1/$2.png"
66 | elif [ -f "arf/img/f1/$2.gif" ]; then
67 | iconString="arf/img/f1/$2.gif"
68 | elif [ -f "arf/img/f1/$2.jpeg" ]; then
69 | iconString="arf/img/f1/$2.jpeg"
70 | elif [ -f "arf/img/f1/$2.jpg" ]; then
71 | iconString="arf/img/f1/$2.jpg"
72 | else
73 | iconString=${icons[0]}
74 | fi
75 |
76 | # add result to alfred, argument should be the entire line
77 | addResult "$line" "$2" "Get details" "$iconString" "no" "$ESCAPE_STRING$line$RESPONSE_STRING$1$PREF_STRING$pref"
78 |
79 | else
80 | addResult "" "ARF+ Error. Enter for details." "Wrong number of parameters provided to addData ($# vs $correctNargs)" "arf/img/sys/error.png" "no" "@args=$line. Make sure to put \$userInput as the first arg"
81 | fi
82 |
83 | else
84 | addResult "" "ARF+ Error. Enter for details." "addData() called before setFieldNames()" "arf/img/sys/error.png" "no" ""
85 | fi
86 |
87 | let "numberOfResults=numberOfResults+1"
88 | }
89 |
90 | # For inputting value names (mandatory)
91 | # Arguments are FIELD1_TYPE, FIELD2_TYPE, FIELD3_TYPE...
92 | # e.g.
93 | # setFieldNames "Name" "Birthday" "Gender"
94 | setFieldNames() {
95 |
96 | # requires at least one argument
97 | if [ $# -gt 0 ]; then
98 |
99 | numberOfFields=$#
100 |
101 | # set field names
102 | i=0
103 | for name in "$@"
104 | do
105 | names[$i]="$name"
106 | let "i=i+1"
107 | done
108 |
109 | # set default icons
110 | i=0
111 | while [ $i -lt $numberOfFields ]; do
112 | icons[$i]="icon.png"
113 | let "i=i+1"
114 | done
115 |
116 | # set default validity
117 | i=0
118 | while [ $i -lt $numberOfFields ]; do
119 | valid[$i]="no"
120 | let "i=i+1"
121 | done
122 |
123 | # set default autocomplete attribute
124 | i=0
125 | while [ $i -lt $numberOfFields ]; do
126 | autocomplete[$i]="no"
127 | let "i=i+1"
128 | done
129 |
130 | # set default argument attribute
131 | i=0
132 | while [ $i -lt $numberOfFields ]; do
133 | argument[$i]=""
134 | let "i=i+1"
135 | done
136 |
137 | else
138 | addResult "" "ARF+ Error. Enter for details." "setFieldNames() received no arguments" "arf/img/sys/error.png" "no" ""
139 | fi
140 | }
141 |
142 | # For inputting default icons for fields
143 | # Arguments are FIELD1_ICON, FIELD2_ICON, FIELD3_ICON...
144 | # Default is icon.png for all fields
145 | # e.g.
146 | # setIcons "arf/img/f1/default.png" "arf/img/f2/default.png" "arf/img/f3/default.png" ...
147 | setIcons() {
148 |
149 | # Check that setFieldNames has been called
150 | if [ $numberOfFields -gt 0 ]; then
151 |
152 | # Loop through all the fields
153 | i=0
154 | arg=1
155 | while [ $i -lt $numberOfFields ]; do
156 |
157 | # check that the argument does not exist
158 | if [ $# -eq 0 ]; then
159 | addResult "" "ARF+ Error. Enter for details." "Not enough parameters given to setIcons() (need $numberOfFields)" "arf/img/sys/error.png" "no" ""
160 | else
161 | icons[i]="${!arg}" # set the icon based on parameter
162 | fi
163 |
164 | let "i=i+1"
165 | let "arg=arg+1"
166 | done
167 | else
168 | addResult "" "ARF+ Error. Enter for details." "setIcons() called before setFieldNames()" "arf/img/sys/error.png" "no" ""
169 | fi
170 | }
171 |
172 | # For inputting validity for fields
173 | # Arguments are FIELD1_VALIDITY, FIELD2_VALIDITY, FIELD3_VALIDITY...
174 | # Default is "no" for all fields
175 | # e.g.
176 | # setValidity "no" "yes" "no"
177 | setValidity() {
178 |
179 | # Check that setFieldNames has been called
180 | if [ $numberOfFields -gt 0 ]; then
181 |
182 | # Loop through all the fields
183 | i=0
184 | arg=1
185 | while [ $i -lt $numberOfFields ]; do
186 |
187 | # check that the argument does not exist
188 | if [ $# -eq 0 ]; then
189 | addResult "" "ARF+ Error. Enter for details." "Not enough parameters given to setValidity() (need $numberOfFields)" "arf/img/sys/error.png" "no" ""
190 | else
191 | valid[i]="${!arg}" # set the icon based on parameter
192 | fi
193 |
194 | let "i=i+1"
195 | let "arg=arg+1"
196 |
197 | done
198 | else
199 | addResult "" "ARF+ Error. Enter for details." "setValidity() called before setFieldNames()" "arf/img/sys/error.png" "no" ""
200 | fi
201 |
202 | }
203 |
204 | # For inputting autocomplete attribute
205 | # When valid is no, Alfred uses the autocomplete attribute to modify the
206 | # user's query to whatever autocomplete is specified as when the user
207 | # selects the option.
208 | #
209 | # In ARF+, if "no" is used in autocomplete, selecting an item changes the
210 | # query to the current query, so nothing happens.
211 | #
212 | # Could be used to jump to specific searches from options.
213 | #
214 | # Arguments are FIELD1_AUTOCOMPLETE, FIELD2_AUTOCOMPLETE, FIELD3_AUTOCOMPLETE...
215 | # Default is "no" for all fields
216 | # e.g.
217 | # setAutocomplete "no" "yes" "no"
218 | setAutocomplete() {
219 |
220 | # Check that setFieldNames has been called
221 | if [ $numberOfFields -gt 0 ]; then
222 |
223 | # Loop through all the fields
224 | i=0
225 | arg=1
226 | while [ $i -lt $numberOfFields ]; do
227 |
228 | # check that the argument does not exist
229 | if [ $# -eq 0 ]; then
230 | addResult "" "ARF+ Error. Enter for details." "Not enough parameters given to setAutocomplete() (need $numberOfFields)" "arf/img/sys/error.png" "no" ""
231 | else
232 | autocomplete[i]="${!arg}" # set the icon based on parameter
233 | fi
234 |
235 | let "i=i+1"
236 | let "arg=arg+1"
237 | done
238 | else
239 | addResult "" "ARF+ Error. Enter for details." "setAutocomplete() called before setFieldNames()" "arf/img/sys/error.png" "no" ""
240 | fi
241 |
242 | }
243 |
244 | # For inputting argument attribute
245 | # The argument is passed to actions.sh if validity for the field is
246 | # set to no.
247 | #
248 | # Arguments are FIELD1_ARGUMENT, FIELD2_ARGUMENT, FIELD3_ARGUMENT...
249 | # Default is "" for all fields
250 | #
251 | # e.g.
252 | # setArguments "" "openHelp" "runScript"
253 | setArguments() {
254 |
255 | # Check that setFieldNames has been called
256 | if [ $numberOfFields -gt 0 ]; then
257 |
258 | # Loop through all the fields
259 | i=0
260 | arg=0
261 | while [ $i -lt $numberOfFields ]; do
262 |
263 | # check that the argument does not exist
264 | if [ $# -eq 0 ]; then
265 | addResult "" "ARF+ Error. Enter for details." "Not enough parameters given to setArguments() (need $numberOfFields)" "arf/img/sys/error.png" "no" ""
266 | else
267 | argument[i]="${!arg}" # set the icon based on parameter
268 | fi
269 |
270 | let "i=i+1"
271 | let "arg=arg+1"
272 | done
273 | else
274 | addResult "" "ARF+ Error. Enter for details." "setArguments() called before setFieldNames()" "arf/img/sys/error.png" "no" ""
275 | fi
276 |
277 | }
278 |
279 | # Creates temporary preferences file out of the user-set fieldnames, icons
280 | # validity, autocomplete, and arguments for each field.
281 | #
282 | # Call once after all preferences have been set
283 | establishPreferences() {
284 |
285 | # add field names
286 | i=0
287 | while [ $i -lt $numberOfFields ]; do
288 | echo -n "${names[$i]}$DELIMITER" >> "$pref"
289 | let "i=i+1"
290 | done
291 | echo >> "$pref"
292 |
293 | # add icons
294 | i=0
295 | while [ $i -lt $numberOfFields ]; do
296 | echo -n "${icons[$i]}$DELIMITER" >> "$pref"
297 | let "i=i+1"
298 | done
299 | echo >> "$pref"
300 |
301 | # add validitys
302 | i=0
303 | while [ $i -lt $numberOfFields ]; do
304 | echo -n "${valid[$i]}$DELIMITER" >> "$pref"
305 | let "i=i+1"
306 | done
307 | echo >> "$pref"
308 |
309 | # add autocomplete attributes
310 | i=0
311 | while [ $i -lt $numberOfFields ]; do
312 | echo -n "${autocomplete[$i]}$DELIMITER" >> "$pref"
313 | let "i=i+1"
314 | done
315 | echo >> "$pref"
316 |
317 | # add argument attributes
318 | i=0
319 | while [ $i -lt $numberOfFields ]; do
320 | echo -n "${argument[$i]}$DELIMITER" >> "$pref"
321 | let "i=i+1"
322 | done
323 | }
324 |
325 | # Allows user to determine the error messages that are displayed is
326 | # The user's search does not receive any results
327 | # The first argument is the large text,
328 | # The second argument is the smaller text.
329 | #
330 | #
331 | # Default:
332 | # No results were found
333 | # Try another search
334 | #
335 | # e.g.
336 | # setError "We couldn't find any results for that query." "Try again later."
337 | setError() {
338 | if [ $# -ge 2 ]; then
339 | err1="$1"
340 | err2="$2"
341 | else
342 | addResult "" "ARF+ Error. Enter for details." "setError() received less than two arguments" "arf/img/sys/error.png" "no" ""
343 | fi
344 | }
345 |
346 | # User does not need to call this.
347 | printNoResult() {
348 | if [ $numberOfResults == 0 ]; then
349 | addResult "" "$err1" "$err2" "arf/img/sys/error.png" "no" ""
350 | fi
351 | }
352 |
353 | # Cleans up strings for compatibility with Alfred XML
354 | # Remove < >, '
355 | # Replace ! with .
356 | # Find out what other characters need to be removed.
357 | tidy() {
358 | echo `echo $1 | sed "s/[<>']//" | sed "s/!/./"`
359 | }
360 |
361 | # needs to be called exactly once at the end of dynamic.sh
362 | pushData() {
363 | printNoResult
364 | getXMLResults
365 | }
366 |
367 |
--------------------------------------------------------------------------------
/arf/lib/common.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # common.sh
3 | # contains common variables
4 |
5 | . arf/lib/workflowHandler.sh
6 |
7 | ESCAPE_STRING="-_arf_-"
8 | RESPONSE_STRING="-_rsp_-"
9 | PREF_STRING="-_prf_-"
10 | DELIMITER='!'
11 |
12 | # generated from workflowHandler.sh
13 | BUNDLE_ID=`getBundleId`
14 | DATA_DIRECTORY="$VPREFS$BUNDLE_ID/"
15 |
--------------------------------------------------------------------------------
/arf/lib/workflowHandler.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | VPREFS="${HOME}/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/"
4 | NVPREFS="${HOME}/Library/Application Support/Alfred 2/Workflow Data/"
5 |
6 | RESULTS=()
7 |
8 | ################################################################################
9 | # Adds a result to the result array
10 | #
11 | # $1 arg
12 | # $2 title
13 | # $3 subtitle
14 | # $4 icon
15 | # $5 valid
16 | # $6 autocomplete
17 | ###############################################################################
18 | addResult() {
19 | RESULT="- $(xmlEncode "$2")$(xmlEncode "$3")$(xmlEncode "$4")
"
20 | RESULTS+=("$RESULT")
21 | }
22 |
23 | ###############################################################################
24 | # Prints the feedback xml to stdout
25 | ###############################################################################
26 | getXMLResults() {
27 | echo ""
28 |
29 | # if [ "${#string[@]}" = "0" ]; then
30 | # echo "- No results foundPlease try another search term
"
31 | # fi
32 |
33 | for R in ${RESULTS[*]}; do
34 | echo "$R" | tr "\n" " "
35 | done
36 |
37 | echo ""
38 | }
39 |
40 | ###############################################################################
41 | # Escapes XML special characters with their entities
42 | ###############################################################################
43 | xmlEncode() {
44 | echo "$1" | sed -e 's/&/\&/g' -e 's/>/\>/g' -e 's/\</g' -e "s/'/\'/g" -e 's/"/\"/g'
45 | }
46 |
47 | ###############################################################################
48 | # Read the bundleid from the workflow's info.plist
49 | ###############################################################################
50 | getBundleId() {
51 | /usr/libexec/PlistBuddy -c "Print :bundleid" "info.plist"
52 | }
53 |
54 | ###############################################################################
55 | # Get the workflow data dir
56 | ###############################################################################
57 | getDataDir() {
58 | local BUNDLEID=$(getBundleId)
59 | echo "${NVPREFS}${BUNDLEID}"
60 | }
61 |
62 | ###############################################################################
63 | # Get the workflow cache dri
64 | ###############################################################################
65 | getCacheDir() {
66 | local BUNDLEID=$(getBundleId)
67 | echo "${VPREFS}${BUNDLEID}"
68 | }
69 |
70 | ###############################################################################
71 | # Save key=value to the workflow properties
72 | #
73 | # $1 key
74 | # $2 value
75 | # $3 non-volatile 0/1
76 | # $4 filename (optional, filename will be "settings" if not specified)
77 | ###############################################################################
78 | setPref() {
79 | local BUNDLEID=$(getBundleId)
80 | if [ "$3" = "0" ]; then
81 | local PREFDIR="${VPREFS}${BUNDLEID}"
82 | else
83 | local PREFDIR="${NVPREFS}${BUNDLEID}"
84 | fi
85 |
86 | if [ ! -d "$PREFDIR" ]; then
87 | mkdir -p "$PREFDIR"
88 | fi
89 |
90 | if [ -z "$4" ]; then
91 | local PREFFILE="${PREFDIR}/settings"
92 | else
93 | local PREFFILE="${PREFDIR}/$4"
94 | fi
95 |
96 | if [ ! -f "$PREFFILE" ]; then
97 | touch "$PREFFILE"
98 | fi
99 |
100 | local KEY_EXISTS=$(grep -c "$1=" "$PREFFILE")
101 | if [ "$KEY_EXISTS" = "1" ]; then
102 | local TMP=$(grep -ve "^$1" "$PREFFILE")
103 | echo "$TMP" > "$PREFFILE"
104 | fi
105 | echo "$1=$2" >> "$PREFFILE"
106 | }
107 |
108 | ###############################################################################
109 | # Read a value for a given key from the workflow preferences
110 | #
111 | # $1 key
112 | # $2 non-volatile 0/1
113 | # $3 filename (optional, filename will be "settings" if not specified)
114 | ###############################################################################
115 | getPref() {
116 | local BUNDLEID=$(getBundleId)
117 | if [ "$2" = "0" ]; then
118 | local PREFDIR="${VPREFS}${BUNDLEID}"
119 | else
120 | local PREFDIR="${NVPREFS}${BUNDLEID}"
121 | fi
122 |
123 | if [ ! -d "$PREFDIR" ]; then
124 | return
125 | fi
126 |
127 | if [ -z "$3" ]; then
128 | local PREFFILE="${PREFDIR}/settings"
129 | else
130 | local PREFFILE="${PREFDIR}/$3"
131 | fi
132 |
133 | if [ ! -f "$PREFFILE" ]; then
134 | return
135 | fi
136 |
137 | local VALUE=$(sed "/^\#/d" "$PREFFILE" | grep "$1" | tail -n 1 | cut -d "=" -f2-)
138 | echo "$VALUE"
139 | }
140 |
141 | getLang() {
142 | defaults read .GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3
143 | }
144 |
--------------------------------------------------------------------------------
/arf/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # main.sh
3 | # Part of the Alfred Reference Framework (ARF)
4 | #
5 | # Calls the correct shell script given alfred input.
6 | #
7 | # [.arf file] [query] [static option]
8 |
9 | # import display function
10 | . arf/scripts/display.sh
11 | . arf/lib/common.sh
12 |
13 | # check for escape string to display data
14 | if [[ $2 == *$ESCAPE_STRING* ]]; then
15 |
16 | # parse out preferences file
17 | preferenceFile=`echo "$2" | sed "s/.*${PREF_STRING}//"`
18 |
19 | displayData "$2" "$preferenceFile"
20 |
21 | getXMLResults
22 |
23 | # run on dynamic mode
24 | elif [ "$3" != "--static" ]; then
25 | echo `./arf/dynamic.sh "$1" "$2"` # Populate data using dynamic.sh and ARF+
26 |
27 | # run on static mode
28 | else
29 | echo `./arf/scripts/search.sh "$1" "$2"` # Use default.arf to get data
30 | fi
--------------------------------------------------------------------------------
/arf/scripts/actions.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # used to handle argument responses
3 |
4 | . arf/lib/common.sh
5 |
6 | userQuery="$1"
7 |
8 | # This file is used for results where validity is set to yes and the
9 | # argument is specified. When one of these types of results is selected,
10 | # this script is called to handle it.
--------------------------------------------------------------------------------
/arf/scripts/display.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # given a type of tea, displays the information about the tea
3 | # the query will be the argument passed to it by alfredTeaSearch.
4 | # arguments:
5 | # [line to parse] [data file]
6 |
7 | . arf/lib/common.sh
8 |
9 | displayData() {
10 |
11 | data=${1#$ESCAPE_STRING}
12 |
13 | # get the number of fields before $REPONSE_STRING
14 | numberOfFields=`grep -o $DELIMITER <<< \`echo "$1" | sed "s/${RESPONSE_STRING}.*//"\` | wc -l`
15 |
16 | # save the names of the fields into an array
17 | # get the first line
18 | nameLine=`sed '1q;d' "$2"`
19 | for i in $(seq 1 $numberOfFields); do
20 | names[$i]=`echo $nameLine | cut -d $DELIMITER -f$i`
21 | done
22 |
23 | # get the second line
24 | iconsLine=`sed '2q;d' "$2"`
25 |
26 | # save the images to use for each field into an array
27 | for i in $(seq 1 $numberOfFields); do
28 | icons[$i]=`echo $iconsLine | cut -d $DELIMITER -f$i`
29 | done
30 |
31 | # get the third line
32 | validLine=`sed '3q;d' "$2"`
33 | for i in $(seq 1 $numberOfFields); do
34 | valid[$i]=`echo $validLine | cut -d $DELIMITER -f$i`
35 | done
36 |
37 | # get the fourth line
38 | autocompleteLine=`sed '4q;d' "$2"`
39 | for i in $(seq 1 $numberOfFields); do
40 | autocomplete[$i]=`echo $autocompleteLine | cut -d $DELIMITER -f$i`
41 | done
42 |
43 | # get the fifth line
44 | argumentLine=`sed '5q;d' "$2"`
45 | for i in $(seq 1 $numberOfFields); do
46 | argument[$i]=`echo $argumentLine | cut -d $DELIMITER -f$i`
47 | done
48 |
49 | # add results
50 | for i in $(seq 1 $numberOfFields); do
51 |
52 | # get the data that needs to be presented
53 | dataString=`echo $data | cut -d $DELIMITER -f$i`
54 |
55 | # check autocomplete value, fill in
56 | if [[ ${autocomplete[i]} == "no" ]]; then
57 | autocompleteString="$1"
58 | else
59 | autocompleteString=${autocomplete[i]}
60 | fi
61 |
62 | # get icon
63 | if [ -f "arf/img/f$i/$dataString.png" ]; then
64 | iconString="arf/img/f$i/$dataString.png"
65 | elif [ -f "arf/img/f$i/$dataString.gif" ]; then
66 | iconString="arf/img/f$i/$dataString.gif"
67 | elif [ -f "arf/img/f$i/$dataString.jpeg" ]; then
68 | iconString="arf/img/f$i/$dataString.jpeg"
69 | elif [ -f "arf/img/f$i/$dataString.jpg" ]; then
70 | iconString="arf/img/f$i/$dataString.jpg"
71 | else
72 | iconString=${icons[$i]}
73 | fi
74 |
75 | addResult "${argument[$i]}" "$dataString" "${names[$i]}" "$iconString" "${valid[$i]}" "$autocompleteString"
76 | done
77 |
78 | addResult "" "Go back" "" "arf/img/sys/back.png" "no" "`echo $data | sed "s/.*${RESPONSE_STRING}//" | sed "s/${PREF_STRING}.*//"`"
79 | }
80 |
81 |
82 |
--------------------------------------------------------------------------------
/arf/scripts/search.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # using users input, finds the matching results
3 |
4 | . arf/lib/common.sh
5 |
6 | MAX_RESULTS=20
7 |
8 | # check to see if the response file exists
9 | if [ ! -f "$1" ]; then
10 | addResult "" "The response file, $1 does not exist." "Make sure the response file is valid" "icon.png" "no" ""
11 | else
12 | query=`echo $2 | tr '[:upper:]' '[:lower:]'`
13 | queriesFound=0
14 |
15 | lineNumber=1 # allows for the skipping of the first two lines, which are the format and the icons
16 |
17 | # loop through the lines of the response file
18 | while read -r line; do
19 |
20 | if [ $lineNumber -gt 5 ]; then
21 |
22 | # get the name of the line
23 | value=`echo $line | cut -d $DELIMITER -f1`
24 |
25 | # convert to lowercase
26 | valueSearch=`echo "$value" | tr '[:upper:]' '[:lower:]'`
27 |
28 | if [[ ( $2 == "all" && ${#value} -gt 0 ) || $valueSearch == *$query* || $teaTypeSearch == *$query* ]]; then
29 |
30 | # get icon
31 | if [ -f "arf/img/f1/$value.png" ]; then
32 | iconString="arf/img/f1/$value.png"
33 | elif [ -f "arf/img/f1/$value.gif" ]; then
34 | iconString="arf/img/f1/$value.gif"
35 | elif [ -f "arf/img/f1/$value.jpeg" ]; then
36 | iconString="arf/img/f1/$value.jpeg"
37 | elif [ -f "arf/img/f1/$value.jpg" ]; then
38 | iconString="arf/img/f1/$value.jpg"
39 | else
40 | iconString=${icons[$i]}
41 | fi
42 |
43 | # add result to alfred, argument should be the entire line
44 | addResult "$line" "$value" "Get details" "$iconString" "no" "$ESCAPE_STRING$line$DELIMITER$RESPONSE_STRING$2$PREF_STRING$1"
45 |
46 | # increment the number of results found
47 | let "queriesFound=queriesFound+1"
48 |
49 | if [ $queriesFound -ge $MAX_RESULTS ]; then
50 | break
51 | fi
52 | fi
53 |
54 | else # increment line number
55 | let "lineNumber=lineNumber+1"
56 | fi
57 |
58 | done < $1
59 |
60 | # if no results were found
61 | if [ $queriesFound -eq 0 ]; then
62 | addResult "" "No results were found for $query" "Check reference file for item" "icon.png" "no" ""
63 | fi
64 | fi
65 |
66 | getXMLResults # return XML to alfred
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cheniel/alfred-reference-framework/a86d650627aa018643e7957c0245d53b65698340/icon.png
--------------------------------------------------------------------------------
/info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | bundleid
6 | com.danieljchen.referenceframework
7 | category
8 | Tools
9 | connections
10 |
11 | 47B98BC9-1DB6-42A8-91E8-8C28BD99BC43
12 |
13 |
14 | destinationuid
15 | 929F29F9-0823-4DFA-9735-92C6B8626DA6
16 | modifiers
17 | 0
18 | modifiersubtext
19 |
20 |
21 |
22 |
23 | createdby
24 | Daniel J Chen
25 | description
26 | Framework for Alfred which makes it simple to create workflows to search and look up user-defined information.
27 | disabled
28 |
29 | name
30 | Alfred Reference Framework
31 | objects
32 |
33 |
34 | config
35 |
36 | argumenttype
37 | 0
38 | escaping
39 | 127
40 | keyword
41 | arf
42 | runningsubtext
43 | Searching {planets}
44 | script
45 | ./arf/main.sh arf/data/static.arf {query} --static
46 |
47 | # To toggle ARF+, which allows for dynamic generation of
48 | # data through the creation of the temporary .arf file
49 | # using user-created dynamic.sh (from scripts)
50 | #
51 | # Remove --static from third argument...
52 | # e.g.
53 | # ./arf/main.sh arf/data/static.arf {query}
54 | # rather than
55 | # ./arf/main.sh arf/data/static.arf {query} --static
56 |
57 |
58 | subtext
59 | If on static mode, type name of {planet}, or "all" to retrieve all data.
60 | title
61 | {ARF Application}
62 | type
63 | 0
64 | withspace
65 |
66 |
67 | type
68 | alfred.workflow.input.scriptfilter
69 | uid
70 | 47B98BC9-1DB6-42A8-91E8-8C28BD99BC43
71 | version
72 | 0
73 |
74 |
75 | config
76 |
77 | escaping
78 | 127
79 | script
80 | .arf/scripts/actions.sh {query}
81 | type
82 | 0
83 |
84 | type
85 | alfred.workflow.action.script
86 | uid
87 | 929F29F9-0823-4DFA-9735-92C6B8626DA6
88 | version
89 | 0
90 |
91 |
92 | readme
93 |
94 | uidata
95 |
96 | 47B98BC9-1DB6-42A8-91E8-8C28BD99BC43
97 |
98 | ypos
99 | 10
100 |
101 | 929F29F9-0823-4DFA-9735-92C6B8626DA6
102 |
103 | ypos
104 | 10
105 |
106 |
107 | webaddress
108 | danieljchen.com
109 |
110 |
111 |
--------------------------------------------------------------------------------