Search
Tuesday
Aug302016

Workflow Example: Stats

Workflow has a statistics calculation action that takes a set of numeric data and performs one f a variety of statistical operations on it. This workflow is simply an example of the use of these statistics.

The workflow begins with a text based list of five numbers. Each number Is held on a separate line which is then split by new line and stored in the Data variable as multiple items of data.

A new Text action then lists the available statistical operations by name. This is again split by new line, but this is passed to a repeat block. Each repeat iteration will therefore correspond to one of the statistics.

The numeric data is passed into a statistical calculation operation defined by the input list and the resulting calculation type and result is appended to a variable called Output. Note by using he variable by name we're bypassing the combining of results if we were simply to add them to a variable.

The results of all of the statistical calculations are then displayed via a Quick Look action.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Weekday or Weekend

This example takes a date and determines if it is a week day or a weekend. The basic approach for this relies on the simple fact that the only days (in English) that begin with the letter "S" are the days of the weekend.

The workflow begins by capturing a date. This is then formatted using the "EEEEE" format string to return the first letter of the day of the week for that date. If this is "S" then an alert is shown identifying the date as a weekend day. If this is not an "S" then an alert if shown identifying the date as a weekday day.

Click to read more ...

Tuesday
Aug302016

Workflow Example: iCloud Persistent Variable

Sometimes you want to maintain data for longer than the duration of a single workflow run. Perhaps you want to access data on subsequent runs of the same workflow or from a run of a different workflow. This is where we want to take advantage of persistent variables.

This example shows how persistent variables can effectively be provisioned by saving data to a file in iCloud and reading it back in. It would be great to do this as JSON as this would easily allow multiple variables to be saved in a single file, but until workflow allows you to write back individual keys into a JSON dictionary it's just much easier to store one data item per file.

The workflow begins by attempting to read in a file that is to hold the variable data. If the file exists it will be stored in a variable. If it doesn't the variable is initialised to zero.

The variable is incremented and saved back to the file. The file is created if it does not already exist and overwritten if it does. The workflow output is the incremented value.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Combining PDFs

The combine list items workflow example takes two lists and concatenates the corresponding entries by position. The first item of the first list and first item of the second list are paired, the second item of each list is paired and so on through to the last item

The workflow begins by creating a list from a set of text. It does this by splitting the lines of text into list items. The workflow then repeats this for a second set of text; producing a second list.

A repeat lop is then used to iterate through the second list. The number of the repeat item is used to fetch a list item (by index) from the first list. These are then concatenated (with a pipe/vertical bar as a separator) within a Text action.

The text is then added to a variable. Each addition creates a new item effectively building a new list in the variable. The variable is then returned at the end of the workflow.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Combine List Items

The combine list items workflow example takes two lists and concatenates the corresponding entries by position. The first item of the first list and first item of the second list are paired, the second item of each list is paired and so on through to the last item

The workflow begins by creating a list from a set of text. It does this by splitting the lines of text into list items. The workflow then repeats this for a second set of text; producing a second list.

A repeat loop is then used to iterate through the second list. The number of the repeat item is used to fetch a list item (by index) from the first list. These are then concatenated (with a pipe/vertical bar as a separator) within a Text action.

The text is then added to a variable. Each addition creates a new item effectively building a new list in the variable. The variable is then returned at the end of the workflow.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Nearest Quarter Hour

This workflow provides an example of working with times and rounding them off. Not simply up or down but to the nearest quarter of an hour.

The workflow begins by capturing a (date and) time. This can be the current (date and )time or one that you specify. This is then reformatted to a short time format.

The resulting time is split (by colon) into two parts - the hours and minutes. The hours are stored in a variable whereas the minutes are then run through a set of calculation operations. The minutes are divided by 15 and rounded to zero decimal places. This will give a value between 0 and 4. That figure is then multiplied by 15 which will give 0, 15, 30, 45 or 60 as a result.

If the minutes are 60 then the workflow sets the minutes to 0 and increments the hours by 1. If the hours are already set to 23 this will be set as 00 rather than 24.

The minutes are then formatted to two digits and the result is displayed via a Quick Look action.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Coordinates for UK Postcode

Workflow can easily leverage the geographic information available to today's iOS devices. In this example the workflow takes a postal code and returns the longitude and latitude for that location. Please note that because postal codes are for a street or small area 'the longitude and latitude are corresponding approximations for those locations.

The workflow begins by capturing a UK post code. It could also be a non-UK postal code if you amend the country in the Street Address action that follows the storage of the post code. The resulting address object I held in the Location variable.

This is then queried for the latitude and longitude. Those details are then combined and output via Quick Look.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Fetch Home Address

Workflow is an amazing piece of software, but it can't always do everything you might want. At least not yet. One such thing that a Twitter user was having an issue with was identifying the home address of a contact. This was simply information iOS contacts hold, but was not directly available to check against within Workflow. There is however a way around this which is what this example is all about.

The workflow starts by saving a contact (you'll need to amend the contact to one of your own) to file in iCloud. This is where the trick starts as the output format is a VCard and this contains some details that allow the address type to be identified. After saving, the workflow capture the file name and then reads the file back in from iCloud (unfortunately there doesn't seem to be a way at this point in time to delete the file from within workflow).

Upon reading it in the file name is altered to give it a .TXT extension. This allows the content to be interpreted by Workflow as plain text.

A regular expression pattern match is then used to find a line where the address type has been set as "HOME". That line is then split (by semi-colon separator) and the five items from the fifth item onwards are captured. These are the five potential address lines.

Theses are finally combined and displayed.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Split by Two New Lines

This workflow is really an example of how to split paragraphs of text where a blank line is used to create a paragraph spacer. More over there is an option within Workflow to split data by newlines, but not by a newline followed by or preceded by something else (e.g. another new line).

The workflow begins with what is probably the key step. Defining the two newlines. Many of the text entry areas are single line and standard tokens such as "\n" are not recognised. As a result a Text action is used and simply contains two new lines. It looks blank … but they are there.

The workflow then saves this to a variable for use later and sets out some example content to be split. Note the use of single and double lines.

The Split Text action is then used to split this text using a custom separator of the variable set earlier.

The result is then displayed and you can swipe through to see the content of each item.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Get Tweet Info

This workflow is an example of how you can get content and meta data information about a specific Twitter post ("tweet") if you have the URL of the post. This includes details about who made the post and when it was made.

The workflow begins by offering to allow you to select an example Tweet URL, to enter your own (custom) URL or to use a URL on the clipboard (there's no validation on this as this is just an example workflow). The workflow takes the tweet ID from the end of the URL (by splitting the URL on the forward slashes and taking the last item). It then appends this to a pre-set Twitter API URL. The URL is then used by Workflow to retrieve a JSON result set from the Twitter API.

At this point the workflow prompts you to select the meta data item to return (name, user name (handle), user profile URL, the actual content of the tweet and the date on which the tweet was posted.

A number of JSON dictionary keys are then used to read in the appropriate data for the tweet. The name and user profile URLs are simple data item retrievals. The user name however is extrapolated form the user profile URL (it's the last part) and prefixed with an "@".

Retrieving the content of the tweet requires a bit of extra work as some extraneous information is stripped out with a bit of splitting and replacing. This extraneous information is the name, user name and date line appended to the end of the content. The upshot is however that a similar approach can be made to extract the date and this can then be reformatted.

You could easily modify this basic example to fetch multiple items and build other outputs; but always note that this workflow is entirely dependent on the Twitter API. If that API changes or if deprecated it is quite possible this workflow will need to be re-worked in some way.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Loop & Pause

This workflow is just an example of how you can use loops and delays and demonstrates a way you could keep checking for something over a period of time and then escape from the checking loop once something has occurred. The example here is based on the user choosing to end the check, but you would more likely set this to be some sort off automated check such as checking that some content has appeared on a remote URL or perhaps a change in state of something on device.

The workflow begins by initialising a couple of variables to be used in the checking. It doesn’t actually matter what the content of these is as long as they are set to be the same. Because of this we can actually use this to hold a particular piece of text that will be of use later in the workflow and make it a little more efficient than setting this text up separately. The workflow sets up a set of actions that will be repeated (up to) five times.

Those actions begin by checking a variable to see if the user has selected to exit the repeated actions. If the check is still matching as “Loop not manually exited” the workflow will pause for two seconds and then display a question to the user asking if they would like to continue in the loop or to stop and exit the loop.

If they choose continue the workflow displays an alert to indicate an action could be run. This is where you might check for a change in a web page or some other change externally or in a device property/state.

If they choose stop checking then the Check variable is set to some informational text stating on which loop the user chose to exit. If this option is chosen, when the loop begins again and the check variable is checked, the app will note that the content has changed from it’s original value. It will repeat the remaining loop iterations, but it will not run any actions other than the check for the change. By having all the actions in the repeat loop inside the If action we can effectively jump out of the loop by doing nothing for all the remaining repeats.

At the end of the workflow an alert is displayed to the user. This contains the content of the check variable. If the user did not choose to stop checking this will contain the original content of the variable. If they did choose to stop it will contain the text indicating that they chose to stop and on which time through the loop they chose to stop.

Click to read more ...

Tuesday
Aug302016

Workflow Example: Send 3 Week Event List

This workflow is an example of how you can fetch sets of information from a calendar and send it to someone. This is a useful basis for sharing your availability with someone and can be easily customised to provide more or less information depending upon how much information you might choose to share with the recipient.

The workflow searches through a particular calendar ("Test Calendar") to find details of all of the events coming up in the next three weeks. It takes each event in turn and extracts the title, start date & time and end date & time. These are collected together as a set of text with a blank line between each event's details.

The workflow takes this set of event information and prompts the user to e-mail the content (where upon it will open up a mail message with the content pre-populated into the body of the e-mail), message the content (to a predetermined recipient '555 123456') or copy it to the clipboard.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Date Difference

This workflow demonstrates the basics of determining the difference between two dates (including dates & time or just time). The example begins with an example date and time against which to do our elapsed time comparison. The user is then prompted to enter a second date. If the Now option is selected, Workflow will use the date and time at that point. If Other is selected, Workflow will prompt the user for input but pre-populate it with the current date and time.

Whilst there is an option to prompt a user to enter the date and time with Ask for Input, if you opt for date & time granularity, only the day, month, hours and minutes are available. Nothing for specifying the year. As a result this example uses a text input and then pulls the date and time from that. Note that the maximum level of granularity is to the minute regardless of if you type in seconds or fractional parts of minutes.

With both dates entered, the Get Time Between Dates action is used to determine the difference. Here the units are specified as Total Time meaning it will give you a full break down of combined time units for the difference, but this could be set to be just seconds, minutes, hours, days, weeks or years. No option for months and slightly surprising that seconds appears given the level of granularity for entering the time.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Get Named Date from Contact

This workflow shows how dates can be read from contacts. The Get Details of Contacts action does not (as of the time of writing) allow custom date fields to be read in from a contact. Instead you must use the Get Dates from Input action. In the workflow the user first selects a contact (ideally with some custom date fields populated) and the workflow then parses the dates returned from the contact - selecting the names of the fields using the Get Name action.

The user is then presented with a list of the available fields and can select one of these to be retrieved. Once selected Workflow parses the list of dates again until it finds one with a matching name (to that selected by the user). The workflow then retrieves the date associated with that field and formats it into the standard short date format.

This is finally returned to the user via a Quick Look action.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Get Web Page HTML

This simple example shows how Workflow can be used to get some HTML for a web page. The workflow asks the user to enter a web page URL. The contents of the URL are then retrieved. The retrieved page is then transformed to HTML using the Make HTML from Rich Text action and the final HTML is displayed to the user via a Quick Look action.

Note that this is a generated set of HTML and will not necessarily match the HTML used on the web page if you view the source of it.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Clipboard Google Search

A very simple example workflow this one but like the majority of the example workflows presented on this site, it's one that was used to help someone online ... so maybe it will be of use to someone else?

This workflow simply takes whatever is on your clipboard, opens a new tab in the Safari browser and passes this as a search to Google. note that this only works for text on the clipboard. If there is something like an image on the clipboard, Workflow will do it's best to pull some text based information from that item (e.g. when it was copied to the clipboard, a URL of an object) and pass that to the search.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Directions Home

This workflow shows how to build a simple workflow to get directions home. The workflow starts with an address (in this case the Apple store in Leeds, UK). The user is then given a list of transportation types to choose from.

Once selected, a Show Directions action is triggered for the Google Maps service with the transportation type selected.

The workflow could be simplified to simply offer the Ask When Run option on the Show Directions. However I prefer to have a nice menu option with the question on it. But there is another consideration. If you wanted to use this as a notification centre widget entry, using the menu option will display the list in situ in the notification centre whereas the Ask When Run approach will bounce the user into Workflow which makes the overall process a little less streamlined.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Dropbox, Save RTF to PDF

This workflow downloads an online rich text file (RTF) and downloads it into the root directory of the user's Dropbox account (overwriting any existing file of the same name).

The workflow then retrieves the file from Dropbox, generates a PDF file from it and saves that file back to the Dropbox root directory (with the same file name as the RTF file … but with a .PDF file extension appended to it).

The PDF file is then opened from Dropbox via a Quick Look action. After this the user is offered the option to save/open it directly into iBooks.

Please note that this is simply an example of some interactions relating to Dropbox, RTF files, PDFs and an external app (iBooks). In reality you would be unlikely to want to keep writing to and immediately reading back from Dropbox - using variables to store files on the device for processing would be much faster.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Text [Remove 'N' Lines]

This workflow takes a block of text and offers to remove a number of lines for the user. The user can select whether to remove them from the beginning or the end of the text and the workflow uses some validation for numeric data entry to put in some better edge case handling.

The workflow starts by storing the text and counting the number of lines in it (ten in this case). It then asks the user how many lines they would like to remove. The input must be a number, but beyond that it is validated by several actions to be a positive integer less than or equal to the maximum number of lines in the text. The input begins by being rounded down to the nearest integer. This is then compared against 0 and the number of lines to ensure it falls between them (inclusively). If it does not then the user receives a notification and is prompted to enter the number again (via a loop that will give the user 42 chances to enter the right number … after which anyone might give up the will to live ;-) )

Once the number has been verified the user is presented with the option to remove the lines from the start or the end of the text.

When removing the lines, the workflow splits the text by new lines and loops through the lines. It uses the index number of the loop to determine whether to retain the line or not. If it should then this is added to an Output variable.

Once the lines have all been processed, the content of the Output variable is recombined (with new lines as the separator) and the lines are displayed to the end user via a Quick look action. Finally an Exit Workflow action is triggered to break out of the loop used to validate the input.

Click to read more ...

Wednesday
Sep302015

Workflow Example: Image Combination & Order

This example workflow demonstrates various ways to combine images in differing orders. In Workflow the combine images action allows you to create a composite image by placing existing images linearly or in a grid and then creating a new larger image.

By default the images are put together in reverse chronological order - i.e. the newest comes first with the oldest at the end (combination starts from the top left). However with a bit of effort that ordering can be changed.

The workflow begins by prompting the user to select how to construct the image. The first option is to auto-select the last "N" images. The user enters the number and then the remainder of the process is automatic. The other two options require a manual selection of images.

Using the time ordering option, the user selects all of the images at once. Using the manual order however, the user will ned to go through a more tedious process. The user first enters how many photos they wish to select and then the workflow loops to allow the user to select that number of images but only one at a time - that's what override's the default time based ordering.

With the images selected and the order effectively set the workflow generates a single row combination of the images in the order specified. This is stored in a variable.

Next the workflow takes the set of images used to generate the composite image and reverses the order by simply reading them back in reverse order from the variable the images are stored in.

This reversed image set is now combined in the same way as before and then this image is added to the variable containing the previous combined image.

The variable holding the two images is then passed to the Combine Images action but this time set to combine vertically rather than horizontally. The final image is then the first row of images (auto-selected & time based, manually selected & time based or manually selected & manually ordered) on the top row and its reverse on the bottom row. The result is displayed via Quick Look action.

Click to read more ...