or Connect
AppleInsider › Forums › Software › Mac Software › How to make a script to open a file/folder ?
New Posts  All Forums:Forum Nav:

How to make a script to open a file/folder ?

post #1 of 9
Thread Starter 
I'm new to scripting in OS X. How can I build a simple script to tell the Finder to open a given folder, and to put the window in front, using Automator ?

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
post #2 of 9
In the command line, it's as simple as:

open "/path/to/folder/or/file.jpg"

So any scripting environment that can run a shell script can execute that with a system call. How do you plan to enter the pathname of the item to open?
post #3 of 9
Thread Starter 
Thanks for the reply.

As for the path, I'm not sure yet. Also, the script should bring the folder or the file to front.

EDIT : Currently, I don't understand how Automator is working. All I want to do is to create a small app that open a specific text file with TextEdit. How am I supposed to do that ?

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
post #4 of 9
Thread Starter 
Okay, I'm beginning to understand now. My first script-app is working exactly as I wanted to.

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
post #5 of 9
Thread Starter 
Well, I now have a problem and I don't know how to solve it :

The script is very simple and just bring the Finder to front and open a folder :

Quote:
tell application "Finder"
\tactivate
\topen POSIX file "/Users/userName/Applications/aFolder"
end tell

I saved the script as an application. When I double-click on it in the Finder, it's doing exactly what I want it to do. However, if I launch the same script-app from another application, the script brings a window to ask the user to run the script or to quit it. This, I don't want . The script should just run without asking anything, like what it already do when directly launched from the Finder.

How can I remove the modal dialog box ?

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
post #6 of 9
Did you add this as a service or to an Applescript menu?

This app can help you make a service if you can't just drop the app in a services folder:

http://wafflesoftware.net/thisservice/
post #7 of 9
Thread Starter 
I tried to add a service, but it doesn't work at all (the service do nothing, while the script itself appears to be okay). I don't understand what is going on.

Geez, why is it so complicated just to open a folder using a keyboard shortcut ? The script is just this :

Quote:
tell application "Finder"
\tactivate
\topen POSIX file "/Users/name/Applications/folder"
end tell

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
post #8 of 9
Quote:
Originally Posted by Kali View Post

I tried to add a service, but it doesn't work at all (the service do nothing, while the script itself appears to be okay). I don't understand what is going on.

Geez, why is it so complicated just to open a folder using a keyboard shortcut ? The script is just this :

It seems like that above service packager is incompatible with Snow Leopard as the service crashes when running. You can use Automator though. Start with a service template. Set it to receive no input and then add an Applescript to the workflow panel. Then save and it will save direct to the services folder for you.

A better option might be to use a 3rd party launcher though as the services menu doesn't show up in all apps like Calculator for example. If you used Quicksilver and bound an Applescript to a command, it would launch from anywhere. Application scripting and key-bindings are something I think Apple really need to improve because they are so useful.

Applescript + Automator + Services just throws more underpowered tools on an already complex feature. The amount of uses it has are few because it still needs programming to use it effectively so absolute novices won't go near it and it's too underpowered for proper developers so you're left with that middle ground and I just don't see many people picking it up.

I think a better option would be to put the scripting menu in the Apple menu so it is always present. Then scrap Applescript. It takes 10 times more code to do something than Python or Ruby and those languages make more sense and are more useful in the long term. Apple have a Python binding for Applescript now anyway.

Applescript doesn't work well internationally because the program delimiters are in English instead of characters.
post #9 of 9
Thread Starter 
I fully agree with you, Marvin. I always though that Apple's way to keyboard shortcuts is ackward, unatural and ineffective. I don't understand how and why they totally scraped it, since we already got some good shareware systems to do simple and efficient systemwide keyboard shortcuts.

Thanks alot for your time and help.

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply

Mac mini 2.53 GHz, 4 GB, NVidia's 9400M.
13" MacBook Pro 2.66 GHz, 8 GB, NVidia's 320M.
OS X Snow Leopard 10.6.8

Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Mac Software
AppleInsider › Forums › Software › Mac Software › How to make a script to open a file/folder ?