Not bad for my first AppleScript. but can anyone help me doubleclick a .LNK and have this script called instead of “choose file” .many thanks for any help in advance, Jaymeister
set f to (choose file with prompt "Select a file to read:")
set x to read (f as alias) as text
set y to ":\\"
repeat while not (x begins with y)
set x to characters 2 thru -1 of x as string
end repeat
set x to characters 2 thru -1 of x as string
repeat while not (x begins with y)
set x to characters 2 thru -1 of x as string
end repeat
set x to characters 2 thru -1 of x as string
set y to ASCII character of 0
repeat with i from 1 to (length of x)
set z to (text i thru i of x)
if z = y then
set x to characters 1 thru (i - 1) of x as string
exit repeat
end if
end repeat
set x to StrTran(x, "\\", ":")
tell application "Finder"
set DiskList to every disk
repeat with ThisDisk in DiskList
set Nod to name of ThisDisk
set Nod2 to Nod & x
if (the file Nod2 exists) then
display dialog Nod2 & " - EXISTS!"
tell application "Finder"
open Nod2
end tell
exit repeat
end if
end repeat
end tell
on StrTran(the_string, search_string, replace_string)
tell (a reference to my text item delimiters)
set {old_tid, contents} to {contents, search_string}
set {the_string, contents} to {the_string's text items, replace_string}
set {the_string, contents} to {the_string as Unicode text, old_tid}
end tell
return the_string
end StrTran
Normally OS X topics belong in the OS X forum, but scripts like this belong in Code Exchange.
finished version of code (thanks to JJ) & method to setup “always called when .LNK files clicked” here…
http://bbs.applescript.net/viewtopic.php?id=17238
on open listOfFiles
--> listOfFiles will be something as:
--> {alias "path:to:file1.lnk", alias "path:to:file2.lnk"}
--> loop and process each one
repeat with i from 1 to count listOfFiles
process(listOfFiles's item i)
end repeat
end open
to process(thisFile)
set x to read thisFile
--> set f to (choose file with prompt "Select a file to read:")
--> set x to read (f as alias) as text
set y to ":\\"
repeat while not (x begins with y)
set x to characters 2 thru -1 of x as string
end repeat
set x to characters 2 thru -1 of x as string
repeat while not (x begins with y)
set x to characters 2 thru -1 of x as string
end repeat
set x to characters 2 thru -1 of x as string
set y to ASCII character of 0
repeat with i from 1 to (length of x)
set z to (text i thru i of x)
if z = y then
set x to characters 1 thru (i - 1) of x as string
exit repeat
end if
end repeat
set x to StrTran(x, "\\", ":")
tell application "Finder"
set DiskList to every disk
repeat with ThisDisk in DiskList
set Nod to name of ThisDisk
set Nod2 to Nod & x
if (the file Nod2 exists) or (the folder Nod2 exists) then
--> display dialog Nod2 & " - EXISTS!"
tell application "Finder"
open Nod2
end tell
exit repeat
else
--> display dialog Nod2
end if
end repeat
end tell
end process
on StrTran(the_string, search_string, replace_string)
tell (a reference to my text item delimiters)
set {old_tid, contents} to {contents, search_string}
set {the_string, contents} to {the_string's text items, replace_string}
set {the_string, contents} to {the_string as Unicode text, old_tid}
end tell
return the_string
end StrTran