![]() |
Finding Paths in AppleScripts
Are there standard AppleScript commands for specifying the path to a folder (like the_Root_HD_or_Partition/Users/the_User_Logged_In/Library/Calendars) without knowing the name of the hard disk or partition or the name of the username of the current user or using a "choose ..." statement to find out?
To put this another way; how do I find the name of the root disk or partition and the username of user who is logged in? Given those, I can construct a path. Finally, it is at least conceivable that the user's directory is not on the root volume, partition, or even the same machine. What then? |
Part of the answer.
use something like Code:
tell application "System Events"Code:
tell application "System Events"below is also a script which I had to use something like that for it to work for others Code:
on open dropped_file |
and just figured this
Code:
set thepath to path to home folder |
Quote:
|
You might want to check out the dictionary of the Standard Additions osax. It includes the ability to get paths to several common folders. Look for "path to" in the file commands.
Code:
set lib_ to (path to library folder from user domain ¬ |
hey Rob, do you know how to get it to work with a applescript bundled app.
(droplet) Its supposed to work with apps, which it does if its something like iTunes, but I can not get it to work with the above?? cheers |
Quote:
|
I would be nice if the
with folder creation worked on Normal folders, save all that if exist crap. |
Quote:
-- Rob |
In the dictionary of the Standard Additions
it has path to: Returns full path name to the folder or application specified path to application support/applications folder/desktop/desktop pictures folder/documents folder/favorites folder/Folder Action scripts/fonts/frontmost application/help/home folder/internet plugins/keychain folder/library folder/modem scripts/movies folder/. .. -- the folder or application to return As you can see it states "path to: Returns full path name to the folder or application specified" This works with iTunes but not with a script.app. Since the scripts are classed as a .app I wondered if there is a way to point to them using this method |
Quote:
For example: Code:
set inputWord to (text returned of (display dialog "Word to translate:" ¬I don't know of a workaround, other than resaving the script.app after every change you make to the script, and launching the app to see if you've succeeded. |
Quote:
If you need the path of an app that isn't running, you might need to get more creative with something like this: Code:
-- The app's signature can be found in the info.plist within the package.-- Rob |
Thanks Guys, just came back to this thread and saw the replies.
|
Just found time to look at this again. and the script now includes the path change. so you can put the app any where, and it will find its contents folder so it can write to the SCP.txt file inside it.
It also will now ask for the server name you want to send to. Code:
on open dropped_file |
Hi all,
On a related topic, I have a renaming script that I have to add the current path at the beginning of the script before executing. Is there a nice little snippet of codes that can ease the pain by providing the script the 'current path' value? Thanks in advance. property sourceFolder : "hd2:gh0075:print:" set filenameList to read file "hd2:gh0075:print:filenames.txt" using delimiter {return} set {oldDelims, text item delimiters} to {text item delimiters, tab} tell application "Finder" repeat with aFile in filenameList set oldname to (sourceFolder & (text item 1 of aFile)) as string set newName to text item 2 of aFile set name of file oldname to newName end repeat end tell |
Quote:
Code:
set my_path to path to me as Unicode text-- Rob |
Or if you mean the folder path to you files.
You must have the window of the folder open, for this script. Code:
tryor the script below by selecting a folder first Code:
try |
I would like the script to know where it resides.
A typical process would be for me to drag this script into a folder containing the files to be replaced, along with the filenames.txt which I create and place in the same folder. This tab-delimited file provides the original and new filenames for the script to work with. For example: This_folder abc.pdf def.pdf ghi.pdf filenames.txt batch_rename.scpt I would like the script to learn the full path of "This_folder" without having to hardcode it into the script manually. Now I'll study all of your replies. Thanks again, all. |
Yes, by 'current path', I do mean folder where the script and files to be renamed reside.
But now, I'm having a little trouble integrating your suggestion into my existing script. I took away the Property section (see my original post) and try to integrate your codes into the Tell section, unsuccessfully. Do I need to restore the Property section, and try to integrate your codes into that section somehow? I'm getting the error "Finder got an error: Can't get text item delimiters." on line 5 below. What does the line "set {oldDelims, text item delimiters} to {text item delimiters, tab}' do exactly? Code:
tell application "Finder" |
Try replacing the line set {oldDelims, text item delimiters} to {text item delimiters, tab} with set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tab}...
(Because this line occurs in a Finder tell block, you need to specify that it's AppleScript's text item delimiters you're accessing/setting; otherwise, Finder is searching its own dictionary for text item delimiters, and coming up empty.) |
That worked! Amazing. Thanks a million. And also thanks to Mark Hunte for the initial help. You guys are great!
Quote:
|
There's a nice list of standard "path to" commands at macscripter.net :
http://macscripter.net/faq/get_the_f...id=17_0_10_0_C |
| All times are GMT -5. The time now is 06:03 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.