Twitter Updates

Showing posts with label Applescript. Show all posts
Showing posts with label Applescript. Show all posts

Friday, 17 July 2009

Applescript What Property?

My apple script (applescript) just made a massive leap forward or at least my unerstanding of how people go about figuring it out. I never could work out how people new what all those scriptable properties where called until now.

Open Script Editor (/Applications/AppleScript/Script Editor.app) may be open a script you have been writting / downloaded.

The really clever bit:
from Script editor File-> Open Dictionary
Now choose the application you are scripting and you will get a browsable searchable list of properties that the script can get and set!

Wednesday, 19 November 2008

Finder show hidden files

To make finder (mac file browser) show hidden files you can use the apple script found here
http://www.macupdate.com/info.php/id/15585

Equivalently you could call this from the command line
$defaults write com.apple.finder AppleShowAllFiles TRUE
$killall Finder

Original source

Tuesday, 9 September 2008

An Applescript Preference Systems

I found the basis for an applescript preference systems at macosxhints.
I have corrected a few typos and here it is.

tell application "Finder"
activate

end tell

(*
Preference system version 1

Chris J. Shull
themacgeek@comcast.net
http://home.comcast.net/~themacgeek/

The code is free. Re-use at will, but please leave this acknowledgement in your code.
Feel free to email me and tell me you've found it helpful!
*)

---Base prefs snippet
set prefname to "net.munkymorgy.pref" --this will be the filename
set prefcontent to "default" --this will be the content of the pref file. NOTE that you can create multiple lines
set prefpath to FindPrefFolder() --finds the path to the user's Prefs folder
set ContentParaNumber to 1 --is the paragragh that will be found in a single preference finder. change it throughout the script to switch paragragh found
---End of Base

--write prefs snippet (overrides original)
if CheckIfExists(prefname, prefpath) is true then DeleteAFile(prefname, prefpath)
MakeAFile(prefname, prefcontent, prefpath)
display dialog (prefpath & " " & prefname)
--end write prefs

---read Prefs snippet
if CheckIfExists(prefname, prefpath) then
set pref to paragraph ContentParaNumber of ReadAFile(prefname, prefpath)
set ThereArePrefs to true
else
set ThereArePrefs to false
end if
if ThereArePrefs then display dialog pref --or whatever you want
---End read

---Subroutines-for-preferences-----------------
on UnixfyPath(stringer, origchar, newchar)
set the testlist to the text items of the stringer
repeat with letter in testlist
set let to letter as string
set orig to origchar as string
if let is orig then
set the contents of the letter to newchar
end if
end repeat
set the newpath to "/" & (the testlist as text)
return the newpath
end UnixfyPath


on MakeAFile(filename, filecontents, folderpath)
tell application "Finder"
do shell script ("echo \"" & filecontents & "\" | cat > \"" & folderpath & "/" & filename & "\"")
end tell
end MakeAFile


on ReadAFile(filename, folderpath)
tell application "Finder"
set filecontent to do shell script "cat \"" & folderpath & filename & "\""
end tell
return filecontent
end ReadAFile

on DeleteAFile(filename, folderpath)
tell application "Finder"
do shell script "rm \"" & folderpath & filename & "\""
end tell
end DeleteAFile

on CheckIfExists(filename, folderpath)
tell application "Finder"
set folder_cmd to ("find \"" & folderpath & filename & "\"")
try
do shell script folder_cmd
set worked to true
on error
set worked to false
end try
end tell
return worked
end CheckIfExists

on FindPrefFolder()
tell application "Finder" to set libpath to path to home folder
set userName to do shell script "whoami"
set UnixPath to UnixfyPath("Users:" & userName & ":", ":", "/")
set prefpath to UnixPath & "Library/Preferences/"
return prefpath
end FindPrefFolder

--End-of-Subroutines-for-preferences-----------------

Turning applescripts into apps

This may seem very simple to those have done it before but it took me a while to figure it out.

Once you have written your applescript and saved it as normal.

File -> Save As and change format to application.
When it is saved it will be a *.app

Wednesday, 6 August 2008

Applescript Resources

From the horses mouth (Took along time to find this link)
http://apple.com/applescript/

http://homepage.mac.com/corrp/macsupt/applescript/index.html

When using apple script to call shell commands
http://developer.apple.com/technotes/tn2002/tn2065.html
Blogged with the Flock Browser