Hi All,
I am new to AppleScript.So, I need help from u all. I am trying to open the a pdf file usuing AppleScript. And here the PDF file and the Script/app are in the same directory. But the problem I am facing that the these files can be any where on the Disk.
So, I was trying to get the current directory. But didnot found any workarround.
Any one, please tell me how to get the curren directory [ no window is open ] and how to open the pdf file
subhasishchat
The path to me command returns the path to the current application, so you can use that as a starting point to navigate to another file in the same directory as the script application. Note that this won’t work when you’re running the script from within Script Editor, since in that case path to me returns the path to Script Editor itself.
set thisLocation to path to me as text
set AppleScript's text item delimiters to ":"
set parentFolder to (text items 1 through -2 of thisLocation as text) & ":"
set targetFile to parentFolder & "filename.pdf" --change to your file's name
set AppleScript's text item delimiters to ""
tell application "Preview"
activate
open file targetFile
end tell
Edit: Tested on a script saved as an application in OS X 10.3.8 and run by opening the app in Finder; not sure if this functionality is the same in Tiger.