Applescript to open application from CD Drive - macos

I have a flash program on CD which i need to auto run when Cd insert in drive.
tell application "Finder"
activate
if exists disk "MYRIAD" then
tell application "Mac"
activate
end tell
end if
end tell
Meriad is my CD name and Mac is my flash application. it fire up the Mac application when i test it from desktop but when i burn it on CD it just open FINDER but nothing else.
Now i have also written code in my flash fla in second line to execute Mac application.
stop();
fscommand ("exec", "Mac");
fscommand("fullscreen", true);
fscommand("allowscale", true);
fscommand("showmenu", false);
i dont understand where i am going wrong.
please somebody help.... Thanks in advance.

There is a couple of ways you can do this.
But try this.
tell application "Finder"
activate
if exists disk "MYRIAD" then
tell application "MYRIAD:Mac.app" to activate
end if
end tell
Make sure you set the correct path in the "tell application "MYRIAD:Mac.app" to activate"
line.
separate each directory with a colon ":" but do not put one at beginning or end of the path to the app.
In my example the fist directory is the CD itself. The no other directories leading to the app.
Also make sure you name the app as it appears in the finder.

Related

Applescript to rename a file in the applications folder

I'm trying to use a script to rename a text file in the applications folder. I'm trying the following
tell application "Finder"
set name of file "File.txt" of applications folder to "File.txt.OFF"
end tell
But this gives an error:
Can’t get file "Text.txt" of applications folder.
Its definitely in there and called that (it's a copy and paste). I then tried removing the folder bit:
set name of file "File.txt" of applications to "File.txt.OFF"
But got another error:
Finder got an error: Can’t set every application to "Text.txt.OFF".
Any help would be much appreciated.
Cheers
applications folder in Finder terminology does not point to the standard folder /Applications. It seems to be a legacy reference to some pre OS X item.
Try this, but you might not have permission to change the name and you are discouraged anyway from putting arbitrary data like text files into /Applications
set applicationsFolder to path to applications folder
tell application "Finder"
set name of file "File.txt" of applicationsFolder to "File.txt.OFF"
end tell
or use System Events
tell application "System Events"
set name of file "File.txt" of applications folder of local domain to "File.txt.OFF"
end tell

Moving .plist from usb drive to local disk using applescript

I've been trying to figure this one out for a while now, and I've hit a bit of a wall.
I have quite a few Macs in my environment, and for inventory purposes I need to copy a file named "Department-Info.plist" from a USB Drive to the following location on the hard drive
Macintosh HD:Library:Application Support:Dell:KACE:
I've come up with a couple of solutions that I thought might work, and believe I'm on the right track. However, I'm not getting the result I'm looking for.
Below is what I've come up with thus far, but I need to complete this task:
tell application "Finder"
activate
set FileToMove to "VOLUMES:DELL KACE:Mac:Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
copy file FileToMove to FinalLoc
end tell
I receive this error message when running this script:
I've also tried using this variation of the script:
tell application "Finder"
activate
set name of document file "Department-Info.plist" of folder "Mac" of disk "DELL KACE" to "Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
copy "Department-Info.plist" to FinalLoc
end tell
However, this yields the following result.
I wondered if anyone could point me in the right direction, or provide resources that I may have missed.
First of all, the command copy assigns a value to a variable, it does not copy files
The correct code is
tell application "Finder"
-- activate is not needed
set FileToMove to "DELL KACE:Mac:Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
duplicate file FileToMove to folder FinalLoc
end tell
However consider that you might not have sufficient access privileges to copy the file.
In this case you need to use the shell to enter an admin password:
do shell script "cp '/Volumes/DELL KACE/Mac/Department-Info.plist' '/Library/Application Support/Dell/KACE/'" with administrator privileges

Applescript Error: Finder got an error: Can’t get folder "~/Library/Services"

Here is my code:
tell application "Finder"
move POSIX file "/Volumes/Toggle Desktop Icons/Toggle Desktop Icons/Install Files/Hide Icons.workflow" to folder "~/Library/Services"
end tell
And it always gets this error: Can’t get folder "~/Library/Services".
Any help? This also needs to work on any mac I run the code on. Without changing the code
Thanks.
There is a system property path to home folder that you could use. And for simplicity sake use the native mac HFS path delimiter ":" to reference the rest of your path.
Try this (adding back in your full source path),
tell application "Finder"
move POSIX file "/Volumes/.../Hide Icons.workflow" to folder (((path to home folder) as text) & "Library:Services")
end tell

Launch Two Applications with Applescript

I have been trying to launch two applications that I created with a single applescript file. (I am using OS X Lion)
The code I am using is:
tell application "app1" to activate
tell application "app2" to activate
Doing either one of these two tells works, but both together only launches the first application...
Does anyone know what I an doing wrong?
The first application is a C application compiled by xCode, and the second application is an AIR/Flash application created/published in Flash CS4
Edit
I've also tried
do shell script "my_path_here/app1"
do shell script "my_path2_here/app2"
which only launches the first application.
I've also tried:
do shell script "my_path_here/app1" & "; my_path2_here/app2"
which STILL only launches the first application.
Edit 2
I've discovered that this script will work:
do shell script "cd my_path_here/ ; open app1 ; cd my_path2_here/ ; open app2"
This accomplishes what I need done, but still leaves open the original problem, as this is a workaround and not a fix... This might shed more light on what the issue could be though.
I couldn't reproduce the issue, so can't tell you why it's happening, but (assuming there's a timing problem) introducing a delay between the application launches may resolve the problem. You'll need to experiment with the delay time.
tell application "app1" to activate
delay 10
tell application "app2" to activate
tell application "app1" to activate
end if
tell application "app2" to activate
end if
Try that and see how it works.
I've discovered that this script will work:
do shell script "cd my_path_here/ ; open app1 ; cd my_path2_here/ ; open app2"
This accomplishes what I need done, but still leaves open the original problem, as this is a workaround and not a fix... This might shed more light on what the issue could be though.

AppleScript Droplet on DMG not working

Hey I have the following AppleScript saved as a Droplet.
It is saved on a DMG file like this one http://dl.dropbox.com/u/1839051/TestDMG.dmg
The Problem is, while some can drag the template onto the Droplet and have it working, when I try to drag the template onto the droplet the crossed-out circle-symbol shows up indicating that this action is not possible. Nothing happens, the file is not copied.
Does anyone have any idea why I have this problem and how it can be fixed?
Thanks in advance guy.
on open thefiles
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
tell application "Finder"
duplicate thefiles to outputFolder
end tell
end open
Rather than using a droplet and having the user to drag the files onto the droplet, why not just make an installer so the user only has to double-click the installer? It would be easier and also probably avoid your problem. I also added some error handling in your code because it's just prudent to do that with shipping code. We also tell the user what happened.
NOTE: you also had an error in your code. The outputFolder is a string. The Finder requires a file specifier. To make the string into a specifier you add either the word "file" or "folder" in front of the string path. Your code may have worked but the proper way to write it is with a specifier. Other applications may not take the string path but they will all take the specifier... so get in the habit of using them instead of strings.
try
-- create the output folder if necessary
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
-- find the templates on the dmg disk
set myPath to path to me
tell application "Finder"
set myContainer to container of myPath
set templateFiles to (files of myContainer whose name extension is "template") as alias list
end tell
-- copy the templates to the output folder
-- NOTE: the script will error if any of the templates already exist
-- therefore we use a repeat loop and duplicate each file separately with a try block
-- around it to avoid errors in case some templates have already been installed.
tell application "Finder"
repeat with aTemplate in templateFiles
try
duplicate aTemplate to folder outputFolder
end try
end repeat
end tell
-- tell the user everything was OK
tell me to activate
display dialog "The templates were successfully installed! You may now use them in Pages." buttons {"OK"} default button 1 with title "Templates Installer" with icon note
on error
tell me to activate
display dialog "There was an error installing the templates. Please manually install them by copying them to the following folder." & return & return & (POSIX path of outputFolder) buttons {"OK"} default button 1 with title "Templates Installer"
end try
This looks to be a permissions issue, and I have to wonder if the differential between those who can and those who can't have something to do with which OS they are running. I'm running Mac OS 10.6 as an administrator and I was unable to perform the action in the DMG. But I was able to perform the action if I dragged both files out of the DMG and onto my Desktop.
If you need to install files in specific locations to the hard drive to support your project, then I would recommend making an installer (and a matching uninstaller as well) as opposed to the setup you have presented.

Resources