I am very new to both automator and applescript. I have created an application that uses automator to print file(s) that are dragged and dropped onto the program icon. it is very simple. In automator, I just run
Print Finder Items
and the program works. Now I need to do more complicated things and I need to figure out how to convert that one command into applescript. I've tried the advice given in multiple stack overflow articles including: Automator to Applescript for Editing Code but it does not help me. How do I convert this to applescript?
tell application "Finder"
set theItems to selection
print theItems
end tell
You need to learn how to find the commands yourself so you can explore what they do. Open AppleScript Editor. Under the File menu choose "open dictionary" and select the Finder. This dictionary tells you everything you can do with applescripting the Finder. Each application has its own dictionary so you need to start looking at these.
That script works on any files you select in the Finder. Good luck.
Related
I'm trying to figure out how to open multiple finder windows at the same time; like opening several at a time.
Arbitrary example:
tell application "Finder" to open (every folder of home whose name starts with "Do")
See also How do I ask a good question?, and show your existing code.
When I want to do something with Finder, I use
tell application "finder"
do something
end tell
Is there a function list that finder can do?
Or for other application?
In AppleScript the terminology of the applications is listed in dictionaries
In Script Editor select menu item File > Open Dictionary… or press Shift Cmd O.
Then choose Finder or another application
tell application "Finder" to say "this is a test"
tell aplication"finder"
activate
repeat 5 times
make new Finder window
end repeat
end tell
I am just learning different coding and know quite a bit about html, css, and javascript. I am completely new to apple script editor.
Since you're new to applescript I'll give you a basic tip to learn. Only tell an application to do something that it knows how to do. Each application knows how to do specific things and applescript knows how to do things by itself too.
I tell you this because the "say" command is an applescript command, not a Finder command. So there's no reason to tell the Finder to say anything. As you get more complex in your scripts you will find errors if you tell the wrong application to do something. As such you can run the say command by itself. Try this and it will work by itself...
say "this is a test"
The easiest way to know what each application understands is to look in the dictionaries. In Script Editor, under the file menu choose "open dictionary". You can choose any application but for this example open the Finder dictionary. You can search through it to find what the Finder knows how to do. You'll notice it doesn't have the "say" command thus you know not to tell the Finder to use the say command. You can type "say" into the search field and you'll see it doesn't return any results.
If you open the dictionary for "StandardAdditions" you'll find say in there. That's additional things applescript knows by itself.
Good luck.
The part tell aplication"finder" has two typos and is missing a space. It should be tell application "Finder"
The whole think should look like this which builds for me.
tell application "Finder" to say "this is a test"
tell application "Finder"
activate
repeat 5 times
make new Finder window
end repeat
end tell
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.
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