Mac Automator App: How to Set Folder - macos

This is probably something simple but its driving me crazy...
I was just able to build my first automator workflow, which is quite basic and uses the Subtitles application to download subtitles for movies in a specific folder.
The Actions are:
Get Folder Contents
Filter Finder Items (to only movie files)
Open finder item with the Subtitle app
It works fine when I execute the workflow from within Automator because it has a "Folder Action receives files and folders added to:" clause in the beginning which tells which folder to use.
However, I want to save that as an application so I can schedule that on iCal but, when I save as an app, the clause which tells the folder is no longer available and looks like I need to pass the folder name as a parameter/argument and I have no idea on how to do that.
So, what I need guidance is on how to have the app executed in iCal while telling it which folder to use.
Thanks in advance...

Just add a "run applescript" action above your "Get Folder Contents" action. Make the applescript code look like the following. Make sure to put your folder path between the quotes.
on run {input, parameters}
return "/Users/username/Desktop/"
end run
Note: a quick way to get a path is to run this in Script Editor and use the result.
return POSIX path of (choose folder)

Related

Automator - Set a variable with the current path of my workflow app

I created this Automator app that creates the folders I need to start a new project, but I need to share it with my team, so instead of telling them to open Automator and set the path (doucments/projects/2020/) by themself. I was thinking that maybe they just can paste it in the 2020 folder, run the app and create the project folders in the same folder.
But I don't know how to set a variable with the current path where my Automator App it's saved. Any ideas? Thanks, guys!
My current workflow
To create a new folder in a specific location of the user's home folder, you can use the the special 'location' variables that automator defines. Click the variables tab button in the upper left corner of the automator window to see the full list of available variables...
So, to create a folder hierarchy like the one shown in the link, but at a standardized location in the documents folder, use a flow like the following:
Since Automator doesn't have a specific variable that gives the location of the created workflow app, if you want a path relative to the app's location you'd use a Run AppleScript action and try to path to me command, but every time I've tried it I've received weird errors which make me think that command doesn't work correctly in Automator. I mean, the following ought to produce the correct result, but it consistently errors out:
Maybe you can make it function...

Apple Automator take screen capture and save to user-specified location

So, I'm trying to use Automator under Mac OS Yosemite to create a service to allow a user to take a screenshot and save it to a location they specify, through some sort of "Save As" dialog. It seemed like it should be easy, but for some reason I'm running into difficulty with it. The screenshot component is easy, using the "Take Screenshot" action in Automator, but it's the saving it to a custom location that's causing me problems.
After trying a few different approaches, it seemed the easiest thing to do was to save the screenshot to a fixed directory/filename from within the "Take Screenshot" action, and then (using AppleScript) rename it in that directory, and move it to the user-specified target directory. So, I added a "Run AppleScript" action to my service. In it, I generate the dialog to choose a file name/path, using the choose file name command in AppleScript. I'm trying to split up the file name from the path, so that I can rename the file I save in "Take Screenshot," and then move it to the path that I'd like to save it at. I can get the full path, but am having problems just getting the filename from the path—and I've tried a variety of suggestions from what I've seen online. In my screenshot, the error shown was from attempting to do
I'm not set by any means on this flow, so if anyone has any better suggestions on how to do what I'm trying to do, by all means please let me know. Otherwise, if someone's able to just tell me how I can extract the filename from the path (and also if there's some special way you have to use that string to rename the file) that'd be great!
AppleScript code pictured in screenshot:
on run {parameters}
set thePath to (choose file name with prompt "Where would you like to save your file?")
tell application "Finder"
display dialog thePath as string
end tell
set UnixPath to POSIX path of (thePath as text)
display dialog UnixPath
end run
I tried this but it didn't work:
set basePath to POSIX path of (parent of (thePath) as string)
Thanks for checking it out!
An easy way would be to use the command line tool "screencapture". It has many options you can choose. See its man page. Here's an example that you can run as an applescript directly or you could put this inside an applescript automator action if you want.
Good luck.
set thePath to (choose file name with prompt "Where would you like to save your file?")
do shell script "screencapture -mx -T1 " & quoted form of (POSIX path of thePath & ".png")
I've created a Folder action in Automator. Choose Desktop. Add Find Finder objects (search: Desktop). Add Move Finder Object and choose your preferred destination. This will automatically move all your screenshots.

Applescript Droplet Text as Input

How can I create a droplet that takes a text selection as input? When I create a script that starts with on run inputText, the resulting application icon will only darken when files are dragged over it.
You can achieve a similar result by using Automator to make a service. Services can be fed selected text, (or urls or files etc) and not just from Finder, but from the right-click contextual menu or the Services menu. You can run applescript inside the Automator script, so basically Automator makes a wrapper for your appleScript. The downside is that it tends to be even slower than applescript.
Dropplets in AppleScript only support files. You can follow #stib's suggestion of using a service with Automator or using the Scripts menu (launch AppleScript Editor and choose AppleScript Editor>Preferences from the menu bar, General in the preferences window and check "Show Script menu in menu bar"). You can then place the script in the /Library/Scripts/ or ~/Library/Scripts folder to have the script appear in the menu. Alternatively, check out FastScripts to include the ability to assign keyboard shortcuts to the scripts and enhanced menu organization.
In applescript, you can create a simple droplet like this:
on open theThing
set fileToRead to open for access theThing --open the file so we can perform operations on it
set myVar to (read fileToRead) --The myVar variable is set to the contents of the dropped file
display dialog myVar --Shows the contents of the file in a dialog; do what you want with the text here
//other code here
close access fileToRead
end open
So, it's not too hard, just make sure you open for access the file first. I hope this helped!
Helpful Links:
http://macscripter.net/viewtopic.php?id=24772: About Droplets
http://macscripter.net/viewtopic.php?id=24745: About File IO
As far as I could tell, this could only be achieved by wrapping the Applescript in a Cocoa application. I don't know Objective-C, but was able to cobble something together. When I get a chance I'll try to clean up a bit and post an explanation.

Renaming Files Sequentially as they are added to a folder using Automator or Applescript

I need to rename image files sequentially as they are added to a folder. ie. image-0001.jpg and image-0002.jpg are in a folder I add test.jpg and it is renamed image-0003.jpg. I have tried automators rename function but it will start over with image-0001.jpg each time a new file is added instead of continuing the sequence.
Any help is greatly appreciated.
You could make this easy on yourself by using a handy application built into the OS called "Folder Actions". Folder Actions contains one or more special handlers, formally known as folder action event handlers, that run when they are triggered by a change in the target folder. I know I'm confusing but I'll do my best.
What you are trying to accomplish requires an adding folder items to event handler. It requires one direct parameter, which can be anything you wish i.e. target_folder. The handler requires an additional parameter as well; after receiving, which should also be a variable name, i.e. these_items. I have composed a script for you that should do the trick. I have added comments that show you what I'm doing when I do it. Here it is:
on adding folder items to the target_folder after receiving these_items
tell application "Finder"
set all_images to every item of the target_folder as list
repeat with i from 1 to the count of these_items --iterates through all the items you dropped in the folder
set this_image to item i of these_items --the current image
set the name of this_image to "image" & (i + the count of all_images) as string --renames the image based on the number of images already in the folder
end repeat
end tell
end adding folder items to
YAY! The script is done! But are WE done? Not quite. We still need to attach the script to a folder (the script won't run if you try to execute it in script editor).
To do this, first save the script as a Script File in the Folder Action Scripts folder in the Scripts folder in either the local Library folder or the current user's Library folder. Create the folder yourself if it doesn't already exist. Next, launch the Folder Actions Setup application by double-clicking it in the AppleScript folder in the Applications folder. In the window that comes up, click the + button under the table on the left (click the "Enable Folder Actions" checkbox if it isn't already checked) to open a standard file browser sheet, navigate to your desired folder, and click "Open". The Choose a Script to Attach sheet automatically opens, listing all the scripts in all of the Folder Action Script folders. Choose the newly-created script, click "Attach", and BAM you are done!
To see the script in action, drag an image onto the folder. The image is instantly renamed, regardless of if the folder window is open. If you have any questions, or if the script doesn't work, just ask me. :)
well without digging through some code and handin you an answer I'll tell you want you want to do
is create a while loop that checks for the existence of image-000 & i where i is a variable of course and if it exists increment i then when the file doesn't exist rename your file.

AppleScript Transmit Script for uploading file to replace itself on web server

So I have this idea for a handy little AppleScript which in my opinion would be very handy in speeding up the process of uploading a local file, to its same location on the server.
In other words, you have to specify the home folder on the server and locally, but once that's finished, it would be nice to just press like "Command" + "Shift" "U" for upload or some other hot key combination not in use by OS X for uploading the currently selected file in the Finder.
I find myself needing to do this a lot, and it will save a lot of time!
Someone please tell me if there is an easier way to do this, but I think this will be a good learning experience on top of it all.
I need some help on how I should get started however..
1) the command line program curl can upload files. 2) if you have a file selected in a Finder window applescript can get the selection. Using those 2 ideas you can automate your task. I don't know the exact curl command but that should be easy to find using google. So you select a file in the Finder and then run the script. The script can be run with a keyboard shortcut as you mentioned or just put it in the Script menu and run it from there.
tell application "Finder"
set selectedFile to item 1 of (get selection)
set selectedFile to selectedFile as text
end tell
do shell script "curl -switchesToUpload " & quoted form of POSIX path of selectedFile
I use Cyberduck which is an ftp client you can set it up so when you double click a file on the server it opens it up in your favorite editor.( textmate is my favorite.) it atuomagiclly downloads and uploads when you save.
this seems like a much better solution to the problem

Resources