smoking bunny Posted May 24, 2014 Share Posted May 24, 2014 (edited) howdy all, first time posting long time user. so, 'hello all, its lovely to be here' what im looking to do is a nice quick way of creating a new file with alfred, BUT, unlike with the 'new file workflow, this one will have setting input to the file. pretty much, a specific creation of a new file. was wondering how to go about this? example ------ say, i want to create a new text file, with some text already in it each time. doenst matter where, just need that text thanks and all the best Edited May 24, 2014 by smoking bunny Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 (edited) or even, iwas thinking of this. could i just include the specific files needed to create the new one? actually, could that be done and be packed so you didnt have to have the files separate and were 'in' the workflow? so all you would need to do is a have a kind of 'copy' function? i guess Edited May 24, 2014 by smoking bunny Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 anyone? im looking at the 'new file workflow' for pointers. but im gusseing you could have something different which does just 'copy' the included files that were to be written into the finder window Link to comment
vitor Posted May 24, 2014 Share Posted May 24, 2014 Please be patient. Excluding Alfred’s (small) team, we’re all volunteers here (as far as I can tell). Three posts in little over an hour does not go over well; that’s not enough time for a reasonable amount of people to even realise this question exists in the forum. I ask you to be reasonable with the amount of bumps on the thread. That said, yes, it is possible, and shouldn’t be too hard. This might actually be helpful to someone else, so I’m thinking of building a full featured workflow to accomplish it, instead of one that is “good enough” to use now. It should be done relatively soon. Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 sorry about the multiple posts. that last one didnt show up in my browser, and i forgot if i had put it in. so please excuse that. cool. well. im just looking at including the files in the workflow, and just trying to 'write' them to the finder window thats open. bt just running into walls with the copying to the finder paste. thanks Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 actually let me try and make this easier for me to understand and explain further. or less i think this is what i want for this specific task so i just want to do a 'hotkey' creation of a txt file which already has some info i want in to be created every time i do the hotkey. rather than having to type it again. i have stored the files i want to 'create' in the finder window, but having trouble getting them to paste into the finder window does that make more sense? im just scouring for copy/paste scripts, but to get the location path of the files [in the workflow itself] is troublesome. since the location/user changes for other users Link to comment
vitor Posted May 24, 2014 Share Posted May 24, 2014 Yes, I understood the question. I still intend to build the workflow, but if you’re in a hurry and have some scripting experience, you can get the path to the frontmost Finder window in a variety of ways, using AppleScript. -- with this method -- if a Finder window is open, it’ll return the path to the frontmost one, else it’ll return the path to the desktop tell application "Finder" to return (quoted form of POSIX path of (insertion location as alias)) -- with this method -- if a Finder window is the frontmost window app, it’ll return the path of the frontmost one, else it’ll return the path to the home directory tell application "System Events" if (name of first process whose frontmost is true) is "Finder" then tell application "Finder" to return (POSIX path of (folder of the front window as alias)) else return (POSIX path of (path to home folder)) end if end tell This (whatever option you choose) will return the path in a way that should be familiar, like when navigating the filesystem via the terminal. To get it as, say, a bash variable, you’d do something like dirPath=$(osascript -e 'tell application "Finder" to return (quoted form of POSIX path of (insertion location as alias))') That, using osascript to execute some AppleScript, would save the path to a (in this case) dirPath variable. After that, you’d just do something like cp "/whatever/file" "${dirPath}". Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 ah fantastic. tahnk you for that. ill have a look and dont worry, i wasnt directing the question at you. as i said, it was more for me to understand it further. kind of thinking out loud, but also means it documented and wont get too confused when reading it back thanks again. though i did have a thought on how i can implement it. and did think to look at the 'new text file with tag' workflow. that seems to have a lot of what i need. so will pick that apart and work it out but, again, thanks ill check it out Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 ok. this will be my last question for this matter which is a definite, i dont need anything high class, so am making it low-brow so im going to go the route of copying 2 files that i have already made. both are lua files, which, when keyworded will create a project file with the 2 files in. pretty much a project starter pack. but after looking through some of the code ive found with bash script, im not getting what i thought i would. so need some tiny bit of help • so im looking to create a new project folder with a keyword. would it be good to store the files in a folder located in the workflow already. and if so, how can this be renamed to what you would call your project. or if not to store them, how can they be 'collected' when created • i was testing this bash script for just copying the file and have put it in, with the right path [though this shows for example purposes], but pasting just using the keyboard on the desktop, did not work cp /path/to/conf_file.txt • im looking to have it create a new folder, with the files located inside. but im trying to name the folder as well, with the files in. i got the mkdir to work fine to the desktop, but am stuck on the renaming of the folder and for it to create on the open finder window. mkdir /Users/lepton/Desktop/newFolderNameIdLikeToSet • should i keep the files that will be put in the folder in a folder itself in the workflow? i think that all im trying to find. im looking around still. so will post something up if i find what i can. will see thanks Link to comment
smoking bunny Posted May 24, 2014 Author Share Posted May 24, 2014 right ive gotten pretty far. which is good. the one and only problem i need help with, is adding the pre-built files. but im close so here is the first parts file action QUERY={query} mkdir "$QUERY/untitled folder" open "$QUERY" then have keyword to activzate the process source includes.sh #Query from user (folder's name) QUERY={query} if [ ! "$QUERY" ] ; then QUERY="untitled folder" fi > "$FILE" echo "$QUERY" > "$FILE" which has a search folder script to save to attach to the previous one tell application "Alfred 2" to search "folder " lastly this is the desitination of where it will be saved source includes.sh #Query from user QUERY={query} #Read line from file folder_name=$(head -1 "$FILE") destination="$QUERY/$folder_name" destination_check="$destination" #Count of existing folders with same name count=1 if [ "$folder_name" ] ; then while [ -e "$destination_check" ] do echo "incrementing count" #increment counter count=`expr $count + 1` echo "current query: $destination_check" destination_check="$destination $count" done < "$destination_check" mkdir -p "$destination_check" echo "final query: $destination" open "$QUERY" > "$FILE" else open "$QUERY" fi now i have the files in the workflow itself, with an 'include.sh'. but cant figure out how to link those files with the created folder. once i get that. its done, and i wont bother whomever for some time include.sh #Working Directories DATAPATH="$HOME/Library/Application Support/Alfred 2/Workflow Data/smokingbunny.makeLOVE" FILE="$DATAPATH/main.lua" FILE="$DATAPATH/conf.lua" #Enable aliases for this script shopt -s expand_aliases #Case-insensitive matching shopt -s nocasematch #First run check if [ ! -e "$FILE" ]; then mkdir "$DATAPATH" touch "$DATAPATH/main.lua" touch "$DATAPATH/conf.lua" fi so this is what i have, just need help with the files being added Link to comment
jdfwarrior Posted May 28, 2014 Share Posted May 28, 2014 So I'm coming in late and it looks like this may have evolved a few times with what you are wanting it to do so... can you give me a quick run down of what you want this to do? What you're wanting to do sounds like it should be pretty quick and easy to get done. I'll help out the best I can and see if we can get you running Link to comment
vitor Posted May 29, 2014 Share Posted May 29, 2014 Since, as said, I was building a workflow for this, it seemed to make more sense to use that time to have it done sooner, instead of spending it reading, understanding, and helping to debug your progress. I understand you’re in a hurry, but I wanted to build something solid that could be useful to many users. That said, if you still want some help with a particular part of yours, feel free to ask, and we’ll take a look at it.Here’s the initial version of the workflow. Link to comment
smoking bunny Posted June 5, 2014 Author Share Posted June 5, 2014 @david ferguson excuse coming back late on this. just doing stuff so it is just to have a hotkey to create a brand new, blank project. and i did get something to some good affect, which i have put on my github. which is good, of sorts. if you give it a try you will see, its just a script actually, that then creates all the files folders etc. but it a bit big in terms of code for my liking this was just to be for a single language, which is lua/love2d. mainly because what it contains, or would like the file to contain is specific. but let me start in explaining what it is im after and steps im going through 1. so for the initial alfred file i would like to store the files that would end up being created, to be stored in the workflow itself. so when i right-click on my workflow and click on 'show in finder', the required files will be stored in that workflow space. 2. when i type 'makelove', this will start the 'alfred is working for makeLOVE' process. to which i then have to put in a project name. 3. when chosen name is done i press enter and it creates on the top-most finder window open. though im looking to change it so you can select what folder it will be saved in through alfred instead 4. the created file should then have been just simply copied from what i had 'stored' in the workflow when first making it. this would then just make a copy to where it is created. so, essentially it is copying over what i had 'stored' in the workflow @vitor ill give your workflow a look-see. though as i have just put, im looking to make one thats just for LOVE2D project generating. but i will give it a look. i think its just so if i really need to add anything specific it wont conflict. this is what im thinking of it thanks again 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