Hey guys, i have set up preferences and all this stuff but it saves as some werid path:
so what i do in the script is convert it to POSIX
set alertScript to POSIX path of alertScript
run script alertScript
But this gives a error
Hey guys, i have set up preferences and all this stuff but it saves as some werid path:
so what i do in the script is convert it to POSIX
set alertScript to POSIX path of alertScript
run script alertScript
But this gives a error
hi sem,
your “alertScript =” code is not really AppleScript. try something like this:
set alertScript to POSIX path of "Macitosh HD:Users:jamesas:Desktop:Junk:Untitled.scpt"
display dialog alertScript
I know the code isnt applescript as the first bit was from a preference file the next bit was a snippet ofthe code. anywho ill try your suggestion
hi sem,
ah, my bad. sorry. still, if the path is assigned, just coerce the POSIX path like this:
set alertScript to "Macitosh HD:Users:jamesas:Desktop:Junk:Untitled.scpt"
display dialog POSIX path of alertScript
Hey, this is just very odd, doing what you say gets me the exact same path as i do with the command i was told to use before and that works but when i specify the path it doesnt :S
set useScript to choose file with prompt "Select"
run script useScript
You don’t use POSIX paths with run script, you use aliases.
This really just boils down to understanding the difference between classes, checking what class AppleScript/scripting additions/applications expect in a given situation - and (if necessary) knowing how to coerce one class to another.
According to Standard Additions’ AppleScript dictionary, the ‘run script’ command should run either script text - or an alias or file reference to a script file.
So this should work directly:
set script_text to "display dialog \"Hello world.\""
run script script_text
When working with files, the correct syntax will depend on the reference. (Some of these may look similar - but check them carefully to identify the differences.) For example:
set alias_reference to choose file of type "com.apple.applescript.script" without invisibles
--> alias "path:to:script.scpt"
set file_specification to alias_reference as file specification
--> file "path:to:script.scpt"
set posix_path to POSIX path of alias_reference
--> "/POSIX path/to/script.scpt"
set file_path to alias_reference as Unicode text
--> "path:to:script.scpt"
(* now any of the following should work *)
run script alias_reference
run script file_specification
run script POSIX file posix_path
run script file file_path
Perhaps the simplest approach is, as Bruce suggests, to use an alias (especially since that’s what the ‘choose file’ command returns).
Well as i was trying to say is for somereason even if i do use the alias path just like the choose file, it still returns a error even though they are BOTH idetically the same, i can see this because i did a display of both varaibles from the choose file and preference
Do you mean you used a display dialog to compare the results, semaja? If so, I’m afraid that wouldn’t really show much difference - since, to display them in a dialog, the results would need to be coerced (explicitly or implicitly) to unicode text.
To demonstrate:
set alias_reference to choose file of type "com.apple.applescript.script" without invisibles
--> alias "path:to:script.scpt"
set file_specification to alias_reference as file specification
--> file "path:to:script.scpt"
set file_path to alias_reference as Unicode text
--> "path:to:script.scpt"
set posix_path to POSIX path of alias_reference
--> "/POSIX path/to/script.scpt"
display dialog ¬
"¢ alias_reference [class: " & alias_reference's class & "]" & return & alias_reference & return & return & ¬
"¢ file_specification [class: " & file_specification's class & "]" & return & file_specification & return & return & ¬
"¢ file_path [class: " & file_path's class & "]" & return & file_path & return & return & ¬
"¢ posix_path [class: " & posix_path's class & "]" & return & posix_path
So, in a dialog, alias and file references may look exactly the same as a file path (because, for the dialog, they’re all Unicode text). Only a POSIX path appears different because of its visibly different form. However, as you’ll also see from the same dialog, there are differences in class.
If you run just the first statement above…
set alias_reference to choose file of type "com.apple.applescript.script" without invisibles
--> alias "path:to:script.scpt"
… you should see the result returned in Script Editor’s Result pane. Note that it starts with alias, indicating its class.
Now let’s go back to your original post:
It errors because, as both Bruce and I tried to explain earlier, the ‘run script’ command isn’t intended to work directly with a POSIX path.
Before any coercion, the class of the variable ‘alertScript’ would seem to be string or Unicode text (it’s not clear how you extracted it before the code you showed). What we’re suggesting is that you coerce that to an alias - rather than convert it to a POSIX path:
set alertScript to alertScript as alias
run script alertScript
Ahh i see now sorry just didnt understand thanks for helping ill try it out now