kylerumble Posted May 31, 2015 Share Posted May 31, 2015 So I started using Alfred a few weeks ago, and just realized how awesome it is, so I decided to put together a WordPress Workflow. I'd like to share it, but I'd also like some feedback on cleaning it up (if needed), and how to create a config file for default settings such as WordPress user, password, email, so that I can keep sensitive data separate from the actual script. I'm running AMPPS for testing, and it all works. I borrowed code from a few different places. Thanks. # MAMP fix path #export PATH=/Applications/MAMP/bin/php/php5.6.1/bin:$PATH #export PATH=$PATH:/usr/local/bin:/Applications/MAMP/Library/bin # AMPPS fix path export PATH=/Applications/AMPPS/php-5.6/bin:$PATH export PATH=$PATH:/Applications/AMPPS/mysql/bin query="{query}" # MYSQL Credentials mysqluser="user" mysqlpassword="123456" # Database Credentials dbhost="localhost" dbname=$query dbuser=$query dbpass=$(openssl rand -base64 16) #WordPress Config admin_user="admin" admin_password="abc123" admin_email="name@example.com" # Create directory for new site cd /Applications/AMPPS/www mkdir $query cd $query # Create Database /Applications/AMPPS/mysql/bin/mysql -u $mysqluser -p$mysqlpassword -e "CREATE DATABASE $dbname;" /Applications/AMPPS/mysql/bin/mysql -u $mysqluser -p$mysqlpassword -e "GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost IDENTIFIED BY '$dbpass';" /Applications/AMPPS/mysql/bin/mysql -u $dbuser -p$dbpass -e "use $dbname;" /Applications/AMPPS/mysql/bin/mysql -u $mysqluser -p$mysqlpassword -e "CREATE USER '$dbuser' IDENTIFIED BY '$dbpass';" # Download latest version of WordPress /usr/local/bin/wp core download # Setup wp-config file with WP_DEBUG enabled /usr/local/bin/wp core config --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass # Install WordPress /usr/local/bin/wp core install --url="http://www.vanwp.ca/{query}" --title="{query}" --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email Link to comment
deanishe Posted May 31, 2015 Share Posted May 31, 2015 (edited) There are a couple of de facto directories for each workflow to keep its data in. By convention, settings and so forth go in ~/Library/Application Support/Alfred 2/Workflow Data/com.your.workflow.bundle.id/ and temp files go in ~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/com.your.workflow.bundle.id/. (Where com.your.workflow.bundle.id is, of course, the actual bundle ID of your workflow.) You don't have to use these specific directories—and Alfred won't create them for you, or enforce their usage in any way—it's just a convention (that almost all workflows follow). There's a bit more information on Shawn's Alfred docs wiki. These data aren't any more secure than in the workflow itself: the main advantage is that updating the workflow won't overwrite your personal settings. Edited May 31, 2015 by deanishe Link to comment
kylerumble Posted May 31, 2015 Author Share Posted May 31, 2015 Thanks a lot for the great information. What I'm not understanding though is how to save a config file inside a WorkFlow that can be distributed. The data location seems to be in a totally different location than the WorkFlow. Take this Workflow for example. https://github.com/gharlan/alfred-github-workflow it has multiple files inside the Workflow folder. This is where I'd want to store the config file and access it, where the other files are. But there is the files download, and then there is the workflow download. So somehow all the files are compiled into a workflow? I'm having trouble finding this information in the Alfred docs. Link to comment
deanishe Posted June 1, 2015 Share Posted June 1, 2015 (edited) You don't save a config file inside a workflow to be distributed. That's kinda the point. Any settings that are user-specific have no place in the workflow itself. Your workflow should have some reasonable defaults. These can be hardcoded in the script or you can include a sample config file that's copied to the default location if no user config file exists. The workflow you linked to includes a workflow library (workflow.php) that provides an API for the workflow to easily set configuration options that workflow.php saves in the proper location. It doesn't include any config files in the workflow itself. Almost all complex workflows use a workflow library that takes care of things like saving settings, caching data and generating XML output for Alfred. It's silly to write all this code yourself. Here's the forum thread with a list of workflow libraries. Alfred's docs can't really provide a proper description of how to write a workflow based on scripts because it supports so many languages. The workflow you're talking about implementing seems to be a relatively complex one. It might be a good idea to read a few tutorials and look at a few other, simpler workflows to get a feel for how they're structured before trying to build something so complex. Here's the tutorial for the workflow library I wrote. I'm told it's very helpful, but it's also very specific to the Alfred-Workflow library and Python. Richard wrote a PHP tutorial here. With regard to compiling a workflow: workflows are basically just zip files. To turn the GitHub workflow you linked to into an .alfredworkflow file, you'd just download the repo, zip it, and then change the extension from .zip to .alfredworkflow. Edited June 1, 2015 by deanishe Link to comment
kylerumble Posted June 1, 2015 Author Share Posted June 1, 2015 Thanks for all your help. Figured it all out! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now