Access file name in Automator from Folder Action - macos

I'm trying to create a simple Automator workflow that will prompt me for where to move and rename a PDF when I download one from the web. I want to use this for downloading my monthly financial statements.
I'm getting stuck at what I thought would be a simple problem: passing the name of the new file(s) from the Folder Action into the Automator workflow.
How is this done? I tried the "Get Specified Finder Items" action, disabling its input, and passed that to "Set Value of Variable" and in turn to "Ask for Conformation" so I could display the name of the file. It seems whatever I try, I cannot find how to pass the name of the newly downloaded files to the Automator workflow.
This seems like it should be simple. Does someone have an example of an Automator workflow triggered by a Folder Action that passes the files into the workflow?

For the life of me, I can never understand Automator. However I believe I can help in this case. The action you are looking for is called "Get Selected Finder Items" -- it is not intuitive, blame Apple for that.
To test out, I created a folder called "automator_action", then I started Automator (in Snow Leopard) and chose "Folder Action". This is the step you will need to figure out if you are using Leopard or earlier OS.
Next, I drag the "Get Selected Finder Items" (under Finder) over to the right pane, then I dragged the "Rename Finder Items" over and customized it. Finally, I saved the action and ready to test it out. You can see the picture presentation of my "script" here:
http://farm3.static.flickr.com/2590/3937364947_33b1a3ab45_o.png
I tested out the action by dragging a file into this folder and sure enough, the action renames it the way I intended. Dragging multiple files also works. Good luck.

Related

How can I add a contextual menu item to all files on mac os x?

I want to add a contextual menu item to all files that allows to copy the file in a special path. And if possible, I want to add an icon to the menu item.
I'm working on mac os x.
This is very easy to accomplish. You will work in Automator and create a Service Workflow. (See info here.)
Since you tagged "Applescript", I assume you know Applescript. Just use an Applescript action within Automator to get the file path(s) and do what you want with them. You could also use the copy action to copy the files.

Auto-updating images folder in Xcode

Is there some a better way to import images to Xcode than dragging them into project/group/subgroup etc... Not mentioning the creating of retina & non-retina version - I know there are scripts for that, but if there was a way to faster this routine it would be great!
The best way that comes to my mind is that I just copy the into proper folder and it appears in the project in associated group in both retina & non-retina versions.
Folder Actions is another option? i.e. right click on a folder i.e. the folder you save the images to from whichever is your favourite editor, click on "Services" then on "Folder Action Setup" and set up an automator workflow to do this.
Set up a simple "move file from..to" workflow i.e. from the folder you save images to, to the folder you have set up as a group in Xcode.

How to load scripts from a custom folder in InDesign? like from a central repository

I would need a folder to be shared on the server and InDesign CS6 would need to load the scripts from that particular location.
Is this possible?
If you just want to include other scripts in your script you can do this:
$.evalFile(new File(mainscriptloc + "/c/some/folder/central.jsx"));
It will load central.jsx into the executing script just like an "include" file.
On a Mac? I found this solution useful:
http://tewha.net/2012/07/make-a-symbolic-link-from-finder/
The best way I found is to create a folder in any place you want your scripts to be (like a server) which is shared with all the users. Then to setup and run the scripts will be more tricky:
Open ExtendScript Toolkit
Open "Scripts" tab
Click on the top-right button and "Add Favorite"
Choose your path to the script and click ok
Now you can click on the drop down on the left and select "Favorites"
Click on the right drop down and click on your folder name
Double click on your script and run it
Now you are running scripts directly from the custom folder.
The startup script cannot be run from there... so it only works with scripts.
We create links in the users individual scripts folders that link back to the actual script in the central repository on Windows. The downside is of course that users will reasonable often accidentally copy the actual script, rather than a link to the script - and then they miss out on future updates to the script.
Below is an example of a typical users 'scripts panel' folder. Each of the shown shortcuts point at a file in our central repository.
When the user opens InDesign these shortcuts appear in their scripts panel the same way a regular script file would.
On a Mac, I suggest using symlinks (a special kind of OSX shortcut - go here for instructions and an Automator workflow download that will create one whenever you need it).
To create a shortcut, simply select the desired folder (recommended) or file located elsewhere on your computer/server and run the workflow (I suggest making a keyboard shortcut to the workflow as described in the instructions). Drag the shortcut created into your inDesign scripts folder and it will appear and operate exactly as the actual script or folder would in your Scripts Panel. Simply click on the link and inDesign will do the rest - you'll never know what you clicked is not the actual folder/file or that it's located elsewhere.
Note: if you create a shortcut to a script file rather than a folder, be sure to remove the extra text the workflow adds to the name (ie. when applied to "MyScript.jsx", the workflow will create a shortcut named "MyScript.jsx symlink". Remove the " symlink" part so inDesign will recognize the shortcut as a script file. Otherwise it will not run).
I've tested this with inDesign CC on my Mac and it works flawlessly.

Changing the name of a Finder context menu item based on current selection using Applescript

When programming I find it convenient to use Finder to explore directories. In the past I would often find myself wanting an easy way to copy the complete path of the selected file or files to the pasteboard (clipboard) which is (as of OSX v10.8.2) a facility that Finder lacks. So being a programmer, I added the desired functionality by adding an Automator Workflow that launches a simple Applescript to the file context menu that appears when a selected file is right-clicked in Finder.
The script works great! It adds the desired functionality and is convenient to use. However, there is a piece of behavior that I'd like to add to the script that I haven't yet been able to figure out how to do. The name of the Finder context menu item that launches the Workflow is "Copy Filename" which is fine when there is only one file selected but when multiple files are selected I'd like the name menu item to change to "Copy Filenames" or perhaps "Copy "+(The # of selected files)+" Filenames".
So my question is this: How do I, using Applescript, dynamically set the name of an item in the file context menu that appears when a selected file is right-clicked in Finder based on the number of selected files?
There is some precedent for this type of behavior. It can be seen when copying selected files in Finder. If only one file is selected the copy menu item in the context menu will read, Copy "somefile.txt" but if five files are selected the copy menu item will read, Copy 5 Items.
You can’t. Well, you could, but it’s really gross and probably not worth the effort. The name shown in the menu is stored in an Info.plist file inside the workflow, so in theory you could write a monitor script that watches the Finder selection and twiddles that file appropriately, and then calls the magic function NSUpdateDynamicServices(), for which you’ll need AppleScriptObjC. (Or you could kill and relaunch Finder, but doing that every time you change the Finder selection would be, shall we say, impractical.)
An interesting enhancement request would be a way to name Service workflows such that the name reflects the selection, so you name your workflow, say, “Copy Path from %”, and the system would substitute “foo.txt” or “5 items” or what have you automatically.
It’s also worth noting that Finder actually does deal in full paths to some extent. Try dragging files into a plain text document -- you’ll get the paths. Or try copying and pasting into Terminal, which knows about the “furl” flavor on the pasteboard.

Accidently removed "Contextual Menu Items " folder, RightClick not working , How to recover?

I was testing an application called iTrash during which it seems like i have deleted the
"Contextual Menu Items " folder as its no longer present and i can no longer right-click
anywhere on my Snow Leopard. I don't have any backups. Can someone tell me how i can recover
that folder or if i can download the files needed to have in that folder (just the original
ones) to regain the Right-click again?
I managed to get around the problem by reinstalling the 10.6.3 update and also by replacing the Track preference file .plist using an app called Pacifist which allows you to look into MacOSX installation Disk or image and search and extract individual files, in my case the default .plist file for the System Menu Trackpad. glad to see the back of this bizarre predicament.

Resources