Run applescript on keystroke
I have a script which I would like to invoke at will via keystrokes. Is there a simple way to do this with or without (preferably without) using third-party programs? My specific application involves a script that moves messages in Mail. Thanks!
You appear to expect 'System Preferences' 'Keyboard & Mouse's 'Keyboard Shortcuts' to perform as a 'launcher' application. It is not. It is used to (re)assign menu item keyboard equivalents, and nothing else.
To launch an application or AppleScript script (or applet) consider 'QuicKeys' (commercial)*, 'Butler' (freeware)*, and / or 'Spark' (freeware), to name a few. Other launchers, other links'.
* - I personally use and like.
Similar Messages
-
iCal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed.
Calendar (not called iCal anymore) does not include that capability any longer, apparently. What you have to do now is go to Automator and create a Calendar Alert action. You can add a Run AppleScript object to the action and paste in your script there, then when you save it, it will become available as a choice in the alert menu in Calendar.
-
Running AppleScript in the background
Okay, yet another problem I'm having that I'm going to bug the community here with.
Is it at all possible to run AppleScript while doing other things? For example, if I wanted my AppleScript to hop online every hour and send me back information from my site could I have it do this while I do other things? Or will I have to wait until it's completed?
Say I wanted to create a script that hopped on my site and sent me the post number of the last post, could I have it do this while I do other things?
Something like
tell application "Safari" to activate
tell application "System events"
tell process "Safari"
(enter code here to get post number and send it to me)
end tell
end tell
I've tried doing it like this and it definitely doesn't work at all if I don't have the Safari window selected at all times, so is there any way in which I can run script in the background while I work on other things or does AppleScript require full control of my computer while it's working?Save this script just like the others I posted. The script will do exactly as you asked.
<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">property helloWorld : "Hello World "
global numChars, charNum, x
on run
tell application "System Events" to set isRunning to exists process "TextEdit"
if not isRunning then tell application "TextEdit" to launch
tell application "TextEdit"
if isRunning then make new document
set name of window 1 to "Hello World"
set numChars to number of characters in helloWorld
set charNum to 0
set x to 0
end tell
end run
on idle
try
tell application "TextEdit"
if x = numChars then
set x to 1
else
set x to x + 1
end if
set charNum to charNum + 1
set theChar to character x of helloWorld
set character charNum of document 1 to theChar
end tell
on error
quit
end try
return 0.1
end idle
on quit
continue quit
end quit</pre> -
Accessing multiple Automator variables in a Run Applescript action
I have an Automator app set up with 4 variables feeding into a Run Shell Script with the following code. And it runs perfectly.
/Applications/Adobe\ After\ Effects\ CC/aerender -sound ON -project $1 -comp "$2" -output $3/$4
However, I need to be able to see the progress of the Script while it processes in the Terminal window. So, I'm setting up a Run AppleScript to tell Terminal to run the script, but I'm getting two problems.
code:
on run {input, parameters}
set aVar to item 1 of input
set bVar to item 2 of input
set cVar to item 3 of input
set dVar to item 4 of input
tell application "Terminal"
activate
do script "/Applications/Adobe\ After\ Effects\ CC/aerender -sound ON -project aVar -comp \"bVar\" -output cVar/dVar"
end tell
end run
Problem 1--Either my syntax or method of setting the 4 variables to access the array of 4 input variables is wrong. And I don't know enough about AppleScript to figure it out.
Problem 2-- AppleScript really doesn't like the spaces in "Adobe\ After\ Effects\ CC" even though the Terminal has no problem with it. But it errors out before it even gets to Terminal.
Any help that anyone can give will be greatly appreciated.The backslash is also used as the escape character in an AppleScript string, so to actually get the character you need to escape it (you can also use the term quoted form of to let AppleScript figure out how to quote the string). To use the variables, you need to use the concatentation operator to mix the variables and text pieces - by putting a variable inside the string the identifier just becomes text.
Your string should look something like:
"/Applications/Adobe\\ After\\ Effects\\ CC/aerender -sound ON -project " & aVar & " -comp " & bVar & " -output " & cVar & "/" & dVar
or perhaps
quoted form of "/Applications/Adobe After Effects CC/aerender" & " -sound ON -project " & aVar & " -comp " & bVar & " -output " & quoted form of (cVar & "/" & dVar) -
Chaining "Get Value of Variable" and "Run AppleScript" actions in Automator
I'm attempting to access a variable I've set in Automator from within a "Run AppleScript Action". On occasion, generally when I start in a fresh new file, I can chain the "Get Value of Variable" action with the "Run AppleScript" action as you would expect.
Most times, though, they will not chain together. I haven't specified that the "Run AppleScript" action should ignore input, but it behaves that way. I've tried everything I can think of, but I'm out of ideas.
Am I going about this all wrong? (Thanks in advance for any suggestions!)
Message was edited by: rch_nashville (for clarity)The *Get Value of Variable* action is another quirky one. I'm not sure what causes it to fail, but sometimes putting another (dummy) action in between gets it to work. You can also access workflow variables directly from the Run AppleScript action, so you might also give that a try:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 680px;
color: #000000;
background-color: #B5FF6C;
overflow: auto;"
title="this text can be pasted into an Automator 'Run AppleScript' action">
on run {input, parameters} -- get values of workflow variables
set output to {}
set theVariables to the name of variables of front workflow
if the result is not {} then
set theVariables to (choose from list theVariables with multiple selections allowed and empty selection allowed)
if result is false then error -128 -- cancel
repeat with someVariable in theVariables
set the end of the output to (get value of variable someVariable of front workflow)
end repeat
end if
return output
end run
</pre> -
The action "Run AppleScript" encountered an error.
Hey,
I'm using EOS utility to tether my camera to my computer and take photos. I'm then using the "linked software" option in eos utility preferences to send it my Automator action. Eos utility is pretending that my automator script is an application.
The goal is that automator sends it to photoshop to run a specific action on it and then save it to a folder where I display the photos on a monitor.
However everytime I take a photo I get this error message:
"The action “Run AppleScript” encountered an error. Check the actionʼs properties and try running the workflow again."
Once I click "ok" then the script will continue running and everything works fine.
This is my run applescript that I'm using in Automator:
"on run {input, parameters}
set input to input as text
tell application "Adobe Photoshop CS5"
open file input
do action "GDaction" from "GDset"
end tell
end run"
I assume there is an issue in the run applescript. Can anyone help me revise it to avoid getting this error message everytime?Sorry, I guess I wasn't clear. I don't think you need to cast the file reference to a text string.
Try this:
on run {input, parameters}
tell application "Adobe Photoshop CS5"
open file input
do action "GDaction" from "GDset"
end tell
end run
or
on run {input, parameters}
tell application "Adobe Photoshop CS5"
open alias input
do action "GDaction" from "GDset"
end tell
end run
I'm not sure what is being passed and what photoshop is expecting. -
Mail Rules window says "No Scripts Installed" next to "Run AppleScript"
I'm trying to create a rule in Mail that will run an AppleScript. But when I choose "Run AppleScript" in the action section of the rule-creation window, the dropdown to the right says "No Scripts Installed".
If I click on that dropdown, it has one option: "Open in Finder". When I choose that, a Finder window opens to the folder Library/Application Scripts/com.apple.mail/. I dropped my AppleScript file into that folder, but when I tried again to make a rule, I still got the "No Scripts Installed" dropdown.
I'm running Mail version 6.3 in OS X 10.8.3.
Any idea how to get this working properly? Thanks.When Finder opens the directory for your AppleScript (in the case of OS 10.9.1, "Library>Application Scripts>com.apple.mail"), make sure your script (not a shortcut to your script) is copied there. Once it is, you will see the script in the dropdown menu where you initially saw "No Scripts Installed".
Hope this helps. -
Packagemaker: need to run applescript from postflight script
Does anybody makes packages using Packagemaker? I need to run applescript from postflight shell script. Generally, when we need to run applescript or any application from shell script we write:
#!/bin/sh
open /Path/to/applscrpt.app
But what to do if all scripts (shell, app's) placed in MyPackage.pkg/Contents/Resources? What path I need to specify? This way:
#!/bin/sh
open ./Contents/Resources/applscrpt.app
doesn't work...The $1 argument that gets passed to your postflight script by the Installer should contain the full path to the package that's currently being installed. So something like this should work...
#!/bin/sh
open "$1/Contents/Resources/applscrpt.app"
Here is some additional info about args and environment variables available to your scripts.
Steve -
Set Mail Signature with Run AppleScript Action inside an Automator workflow
Hello,
Not sure if I am posting this at the right spot, but I would need some assistance. I am trying to write an Automator Workflow application. The purpose for this application is to:
1. Drag one or more attachments on the application/droplet icon
2. Automator workflow creates a new mail message in Mail with the attached items already addressed and ready to go to
I setup the following Workflow inside Automator:
1. New Mail Message
2. Add Attachments to Front Message
So this is all working just fine. Now I would like to add a step in between of type "Run AppleScript". In this "Run AppleScript" action I have the following code:
on run {input, parameters}
tell application "Mail"
set the message signature of input to signature "My Signature Name"
end tell
return input
end run
So my workflow looks now like this:
1. New Mail Message
2. Run AppleScript
3. Add Attachments to Front Message
I am getting the following error:
Can’t make «class situ» "My Signature Name" of application "Mail" into the expected type.
So, in essence I am trying to select a signature for that particular new mail message in this workflow. And that does not work. Any help would be appreciated.
Martinfirst, you don't need the extra action to add attachments. if you drop some items on the saved application they will be passed to the "new Mail message" action as input and will be added as attachments. also, in my testing it seems that the processes of attaching the attachments seem to bump against the process of adding the signature. it get the same result as you originally but if I add a delay to the run applescript action then it works as it should so try
1. new mail message.
2. run applescript
on run {input, parameters}
delay 1
tell application "Mail"
set the message signature of (item 1 of input) to signature "My Signature Name"
end tell
return input
end run -
Running Applescript /VBScript code using NativeProcess
I know how to run a script file using NativeProcess, but I can't seem to figure out how to run pure script code.
Is there any way to run AppleScript and VBScript code without first saving it to a file?
HarbsThe script is the same. What do you mean your suspicion of executing AppleScriptObjC is wrong?
Macbook pro, fully up to date.
See the first 2 posts in this thread for the crashes. When I comment out the error code it doesn't crash. Rather, Xcode logs
Runtime error in script: (null)
Else, the app crashes pointing to thread 1. Specifically the app stops on the error part of the method. Here is exactly what I'm seeing:
EDIT:
I just printing the scripts path to the console to check if it's being included in the app bundle, which it is. -
Automator Applications don't let me run applescripts!
ok just made an excellent automator application that deleted invisible files on selected drives. the only problem is that when i run it as an application, it gives me an error message and tells mr to check the "Run Applescript" action's properties. But, it works in the workflow perfectly!
please help.OK, that does help. The statementset y to (value of variable "path" of front workflow)uses Automator terminology - unless your workflow is actually running in Automator, your script won't know anything about those terms unless you target the Automator or the Automator Runner applications.
In this case though, you don't need to use variables at all, since the value you want is in the input parameter of the *Run AppleScript* action (this is what is output from the previous action). Note that the input parameter is a list, so you need to repeat through the items in the list or coerce it from a list to the desired class. Your Terminal scripting also seems to be a bit severe, but with the items I noted your workflow would be something like:
1) *Ask for Finder Items* { Type: Folders } (Allow Multiple Selections is not checked)
2) *Run AppleScript*
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #DAFFB6;
overflow: auto;"
title="this text can be pasted into an Automator 'Run AppleScript' action">
on run {input, parameters}
set y to input as text -- coerce from list
display dialog "Are you sure you want to delete the Trash folder on flashdrive " & quoted form of y & "?" buttons {"Cancel", "Yes"} default button 2
display dialog "Enter password:" default answer "password" buttons {"Cancel", "OK"} default button 2
set x to (text returned of result)
tell application "Terminal"
delay 2
do script "cd " & quoted form of POSIX path of y -- convert path
do script "sudo rm -rf .Trashes" in window 1
delay 2
do script x in window 1
delay 2
do script "yes" in window 1
delay 2
do script "killall Terminal"
end tell
return input
end run</pre> -
Running AppleScript on another account or automatic user switching
So here's my issue, in order to do what I want I need to constantly have a window open that cannot be closed. I do not want to always have a window open while I'm using my computer that I can't close since it will be an extremely annoying burden.
So, I was curious if there was a way in which I can run my program on my other user account allowing me to still use my main account. Keep in mind my applescript uses keyboard functions and requires having my browser open and internet connection to send information to my friend.
Since I highly doubt this is possible, my second inquiry was whether or not there is a simple way to switch between users. This way I can have uptime and downtime in which my program will switch users, run the program and then switch back. Unfortunately, there doesn't seem to be any keyboard functions to toggle the quick switch between users.
When trying to figure this out I found this but I don't understand what this means or what programming language it is.
If anyone has any information regarding this think may be useful it would be very much appreciated, even if you don't have a solution. Thank you.
Message was edited by: eGeekee- If the "other" account has administrative privileges then just try changing the PW for your account.
- Forgot Mac Password? How to Reset Your Mac Password (with or without CD)
Change the Admin Password with Mac OS X Single User Mode
Reset mac mini admin password: Apple Support Communities
- If the problem is due to a bad KB just get a new KB -
How Do I Run AppleScripts In Aperture?
I want to copy the Version Name to the Object Name field without having to manually type it for each image...
Here is the script I am attempting to run:
tell application "Aperture"
set selectedImages to the selection
repeat with i in selectedImages
set tName to name of i
set value of IPTC tag "ObjectName" of i to tName
end repeat
end tell
(I copied the script from this thread: http://discussions.apple.com/thread.jspa?messageID=4458642.)
I enabled the Script Menu to appear in the Finder Menu Bar, but that is as far as I have been able to get. I tried selecting a couple of images in Aperture, then selected Batch Change/IPTC Basic. I then selected the script in the Script Menu and clicked "OK." Nothing appears to get transferred in the two selected image files metadata. I also tried running the script without going to Batch Change and Still No Go...
I think that my problem has to do with this step from the linked thread, but I am unclear as to what it means:
4. IMPORTANT! You must use Batch Change to put a value into the Object Name tag (such as " "), until you do so the tag doesn't exist for those images and therefore cannot be altered.
I have been through the Aperture Manual, Apple Aperture Digital Workflow book, etc. but I have been unable to figure out how to make this work.
Message was edited by: MisterMojo
Message was edited by: MisterMojoSince you have OS 10.5.8, do you also use an older Aperture version? Most people have latest OS and Aperture, so you might get more answers if we knew what your version of Aperture is...
Well, I am running OS 10.6.2 and Aperture 2.1.4
I found the script you posted to be non-functional. After digging around and some Googling, I came up with the following script that works for me. Keep in mind you are using a different OS version, but my point is, with some research and trial&err you should be able to do the same. I don't know anything about scripting, all I did was read into its meaning and substitute some terms. I basically stole the code and changed a couple of variables...
tell application "Aperture"
copy selection to theSel
repeat with theImg in theSel
tell theImg
set MyVersionName to (get value of other tag "VersionName" of theImg)
make new IPTC tag with properties {name:"ObjectName", value:MyVersionName}
end tell
end repeat
end tell
Notice how the script temporarily (?) creates a variable called MyVersionName, as a place to hold the value copied over from VersionName. Apparently scripts ignore the spaces in field names. It then uses the value from MyVersionName to fill in the ObjectName. The script is set to repeat for each image selected, one by one. I don't know why it's written like that, but it works.
The above script works for both single and multiple selections of images. Pase it into AppleScript Editor, run it, save it in the Aperture folder which is a straight shot from the Save As... menu in the AppleScript Editor. (Users> {you}> Library> Scripts> Applications> Aperture)
In the ASEditor's Preferences, make sure to check boxes so the scripts appear in the menu bar. Close the Editor. Back to Aperture, your (appropriately-named) script should show up from a drop-down at the menu bar under the AppleScript icon. Test it on a couple of inages. Mine works. -
Error 10810 when running applescript remotely
So "final" product here. I'm no applescripter so my code is probably inefficient. As such I keep running into a -10810 error and from my googling and research I think it's a runaway process (or a few of them) created by this script. I run it through Casper remote. It's a compiled script for compatibility with Casper Remote. Running as a standalone app (or as a compiled script on the local desktop) it works just fine. It's only through Casper Remote that I get this error and only sometimes. The script works even when no one is logged in. Casper Remote runs as an admin and forces sudo when it needs to.
Any ideas as to what might be causing the failure? The script fails very quickly when it does. It certainly does not get to the point where it gathers all apps on the computer.
TIA!
Andrew
(*This script should be run first on a computer to be upgraded.
It collects the size of the users's homefolder and any folders
common to all users (Workfolder, PAGEFOLDER, etc). Common units get
all users transfered. It also collects apps installed in /Applications. It is to
be run again on the new computer to verify that all data and apps were
copied over correctly. It outputs the data to a log at
/netappv2/MacPackaging/FY12MacDAC-UserMigration titled with the
User's username, old mac name *)
on run argv
-- Define static variables --
---- "\n"
-- Capture the user's name (passed from Casper Remote)
set userName to item 4 of argv
-- if a username was not passed to the script, quit immediately
if userName = "" then
do shell script "echo No username specified! Try again with a valid username"
error number -128
else if userName is in {"Common", "common", "COMMON"} then
do shell script "echo **********THIS IS A COMMON UNIT. ALL USERS WILL BE TRANSFERED! **********"
end if
-- Capture computer name and current date
set computerName to computer name of (system info)
set currentDate to current date
-- Define file access --
-- We first have to create a file so we can reference it via Applescript for writing. We do this via the shell
set shellLogFile to computerName & "-" & userName & ".txt"
do shell script ("mkfile 10k /private/var/root/Desktop/" & shellLogFile)
-- Make a directory on the server particular to this user and computer since two reports will be made: one for the old computer and one for the new
set logFolder to computerName & "-" & userName
do shell script "mkdir -p -m 777 /Volumes/MacPackaging/FY12MacDAC-UserMigration/" & logFolder
-- Open a text file for writing the DAC data collection information. Alias it to the file we just created
-- the file is located on roots desktop, but it is aliased to the current user's desktop (if one is logged in)
set logFile to (((path to desktop) as string) & computerName & "-" & userName & ".txt") as alias
open for access logFile with write permission
set eof of logFile to 0
-- Write log headers --
-- Write relevant user and computer information to the log file
if userName is equal to "common" then
write "**********THIS IS A COMMON UNIT. ALL USERS WILL BE TRANSFERED! **********
" to logFile
write "
" to logFile
end if
write "Report run date: " & currentDate & "
" to logFile
write "User to be migrated: " & userName & "
" to logFile
write "Computer to be migrated: " & computerName & "
" to logFile
write "=========================" & "
" to logFile
write "
" to logFile
-- Begin data collection output --
-- First check for the existence of partition "work"
write "Folders on Work partition to be transfered" & "
" to logFile
write "========================================" & "
" to logFile
set workPath to "Work" --we are only looking for partition "Work"
tell application "System Events"
if workPath is in (get the name of every disk) then -- list all partitions and check for "Work." If found, set folderList to the contents of Work
set folderList to list folder workPath without invisibles
else
set workPath to (get the name of every disk) -- if "Work" is not found, list the mounted partitions and exit
write "No Work partition! Available partitions are: " & workPath & ". Exiting." & "
" to logFile
do shell script "echo No Work partition!"
do shell script "echo Available partitions are: " & workPath
close access logFile
error -128
end if
end tell
-- Next write the root level contents of the Work partition and their sizes. These main folders and their entire contents (except Users) will be transferred. For user folders, only the /Users/username and Users/Shared folder will be transferred
set totalSize to 0 --set a count for the size of each folder found. This will be the total size of all data to be migrated
repeat with aFolder in folderList
if aFolder contains "Users" then
set userFolder to "/" & aFolder & "/" & userName -- rename the folder to the explicit path to the users home folder (name provided when the script was run), since we aren't interested in any other user folder
set sharedFolder to "/" & aFolder & "/Shared" -- create another variable to hold the Shared folder since we need to copy this as well
set UNIXFolder to quoted form of POSIX path of userFolder
set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of the users home folder
set totalSize to totalSize + folderSize
write userName & " home folder - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "
" to logFile
set UNIXFolder to quoted form of POSIX path of sharedFolder
set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of the Users/Shared folder using the same method as above
set totalSize to totalSize + folderSize
write "Users/Shared - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "
" to logFile
else if aFolder does not contain "Users" then
set UNIXFolder to quoted form of POSIX path of aFolder
set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of aFolder if other than "Users"
set totalSize to totalSize + folderSize
write aFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "
" to logFile
end if
end repeat
write "____________________" & "
" to logFile
write "Total copy size: " & CalcFolderSize(totalSize) & " " & KBMBGB(totalSize) & "
" to logFile
write "
" to logFile
-- Record all departmental apps that need to be installed on the new mac
write "Departmental apps to install on the new mac" & "
" to logFile
write "===========================================" & "
" to logFile
-- A pre-defined list of departmental apps. These apps are not included in the AG Core image and need to be installed on the new mac. All relevant transferrable apps are in the Applications and Utilities folders. Apps installed elsewhere are not AG standard and do not get transferred
set theApps to {"Adobe Acrobat 7.0 Professional.app", "Adobe After Effects CS4.app", "Adobe After Effects CS3.app", "Adobe Fireworks CS3.app", "Adobe Flash CS4.app", "Adobe Flash CS3.app", "ColorEyes Display Pro.app", "ColorThink 2.2.1b2", "Corel Painter X.app", "DiskTracker 2.3.2", "DiskTracker.app", "Dreamweaver.app", "EPSON Scan.app", "Fetch.app", "formZ RenderZone Plus.app", "Google Earth Pro.app", "Google Earth.app", "iMovie.app", "Keyspan Serial Assistant.app", "Flash 8.app", "Microsoft Excel.app", "Microsoft Excel", "Microsoft Word.app", "Microsoft Word", "Microsoft PowerPoint.app", "Microsoft PowerPoint", "PhotoZoom Pro 2.app", "Product Ingest.app", "Product Tag.app", "Art Ingest.app", "ProfileMaker", "TextWrangler.app", "Toast Titanium.app", "ToolCrib.app", "Winclone.app", "Suitcase Fusion 2.app", "Suitcase Fusion 3.app", "BRASS.app", "Final Cut Pro.app", "Pro Tools LE.app", "LightWave", "VMware Fusion.app"}
set appsPath to (path to applications folder)
tell application "Finder"
set appList to name of every application file of entire contents of folder appsPath
end tell
repeat with anApp in theApps
if appList contains anApp then
set anAppID to id of (application anApp)
if anAppID is not equal to "????" then
tell application "Finder" to tell (application file id anAppID)
set vers to version of application file id anAppID
set parentFolder to name of its container
end tell
if parentFolder is in {"Applications", "Utilities"} then
set parentFolder to ""
end if
write anApp & "
" & "Version: " & vers & "
" & parentFolder & "
" to logFile
write "--------------------------------------" & "
" to logFile
write "
" to logFile
else if anAppID is equal to "????" then
write anApp & "
" to logFile
write "--------------------------------------" & "
" to logFile
write "
" to logFile
end if
end if
end repeat
write "
" to logFile
-- Collect all the printers that need to be installed on the new Mac
write "Printers to install on the new mac" & "
" to logFile
write "===================================" & "
" to logFile
(*tell application "Printer Setup Utility"
set printerList to the name of every printer as list
end tell
repeat with aPrinter in printerList
write aPrinter & "
" to logFile
end repeat*)
set printerList to do shell script "lpstat -a | awk '{print $1}'" as text
write printerList & "
" to logFile
close access logFile
-- edit file permissions so everyone can read it
do shell script "chmod 755 /private/var/root/Desktop/" & shellLogFile
-- copy the file to macpackaging for later use
do shell script "ditto /private/var/root/Desktop/" & shellLogFile & " /Volumes/Macpackaging/FY12MacDAC-UserMigration/" & logFolder
end run
-- subroutine for converting folderSize
on CalcFolderSize(KBParam)
if KBParam ≥ 1048576 then -- convert to GB
return (KBParam / 1024 / 1024)
else if KBParam ≥ 1024 then -- convert to MB
return (KBParam / 1024)
else
return (KBParam)
end if
end CalcFolderSize
-- subroutine for determing KB, MB, or GB
on KBMBGB(paramSize)
if paramSize ≥ 1048576 then -- 1GB
return ("GB")
else if paramSize ≥ 1024 then -- 1MB
return ("MB")
else
return ("KB")
end if
end KBMBGBSo AS can't get the physical size of the folder it finds. I think I know the reason though. The script lists the contents of the Work volume in this snippet:
set workPath to "Work" --we are only looking for partition "Work"
tell application "System Events"
if workPath is in (get the name of every disk) then -- list all partitions and check for "Work." If found, set folderList to the contents of Work
set folderList to list folder workPath without invisibles
else if
... stuff ...
end if
end tell
Then later I have it doing this:
else if aFolder does not contain "Users" then
tell application "System Events"
set folderSize to (physical size of aFolder) div 1024
end tell
set totalSize to totalSize + folderSize
write aFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "
and I get the following from the AS editor events pane:
tell current application
system info
--> {AppleScript version:"2.1.2", AppleScript Studio version:"1.5.1", system version:"10.6.7", short user name:"acaldwell", long user name:"AC Andrew Caldwell (8318)", user ID:1.092545022E+9, user locale:"en_US", home directory:alias "Work:Users:acaldwell:", boot volume:"AG2025", computer name:"AG2025", host name:"ag2025.amgreetings.com", IPv4 address:"10.104.20.113", primary Ethernet address:"00:17:f2:07:ec:dc", CPU type:"Intel 80486", CPU speed:2660, physical memory:4096}
current date
--> date "Wednesday, June 8, 2011 4:24:49 PM"
path to desktop as string
--> "Work:Users:acaldwell:Desktop:"
open for access "Work:Users:acaldwell:Desktop:AG2025-acaldwell.txt" with write permission
--> 47
set eof 47 to 0
write "Report run date: Wednesday, June 8, 2011 4:24:49 PM
User to be migrated: acaldwell
Computer to be migrated: AG2025
=========================
" to 47
write "Folders on Work partition to be transfered
========================================
" to 47
end tell
tell application "System Events"
get name of every disk
--> {"AG2025", "Work", "home", "net", "Public", "MacPackaging"}
list folder "Work" without invisibles
--> error number -10004
end tell
tell current application
list folder "Work" without invisibles
--> {"Page4 Folder", "PAGE4BUILDER", "Users", "zz_LastFolder"}
Result:
error "Can’t get physical size of \"Page4 Folder\"." number -1728 from «class phys» of "Page4 Folder"
Now I tested the tell system event portion in another editor with this code
set aFolder to path to home folder
tell application "System Events"
set folderSize to (physical size of aFolder) div 1024
end tell
and got the right result. So I think that I can't get the size because it is not showing the path to each of these items, just the name of them. Is there a way to set a variable to the path to each of the items it finds? I think then it'll get the sizes right....
Thanks!
Andrew -
Wake computer from sleep automatically to run applescript
Hey guys, here's a problem for you to figure out. I just recently learned some very basic terms for applescript so I figured I'd make an alarm clock to wake me up. I'm looking for some kind of code or program that can wake up the computer just like the Schedule in Energy Saver does, but in a more flexible way.
This is the code I use for the alarm clock;
set volume 0
tell application "Finder"
activate
open internet location file "lightningstream.surfernetwork.com/.webloc" of folder "Site Shortcuts" of folder "Desktop" of folder "Nick" of folder "Users" of startup disk
end tell
delay 15
set volume 1
delay 0.25
set volume 1.5
delay 0.25
set volume 2
delay 0.25
set volume 2.5
delay 0.25
set volume 3
delay 0.25
set volume 3.5
delay 0.25
set volume 4
delay 0.25
delay 4
set volume 2
So this sets the volume to 0, opens up a radio stream, then increases the volume and lowers it. On weekdays this works without a problem because i set the Schedule in Energy Saver to wake the computer on Weekdays at 5:51 AM and then have iCal run the applescript at 5:55 AM. But if i wanted to wake up later in the day on the weekend then I would have to wake the computer to get the script to run.
I'm looking for some kind of code or program that can wake up the computer just like the Schedule in Energy Saver does, but in a more flexible way.
Now I realize that there is a sleep and a doze. Usually my computer is in doze because I have a security camera program that runs on it's own schedule. Eventually that shuts off and my Mac sleeps. So i need some way to tell the computer to wake at a specific time from sleep with me having to manually wake it. Any ideas?If you're comfortable with the command-line environment (i.e. Terminal.app) you can use the "pmset" command to schedule individual, non-repeating sleep or wake events.
For example:
sudo pmset schedule wake "07/04/11 20:00:00"
Will wake a sleeping mac at 10AM on July 4th 2011. (And only at that date and time, not any other time.)
For more info on "pmset", execute "man pmset" at the command line.
Why Apple doesn't build a more flexible scheduling function into the Energy Saver sleep-scheduler (or better yet, right into iCal) I don't know, but the low-level functionality is already easily accessible, right there in the pmset command.
Depending on your needs, you could write an Applescript or even a fully-fledged application program as a graphical front end to the "pmset" command-line utility. For example, you might use iCal's ability to hand off event data to Applescript as follows:
- Create a schedule of sleep & wake events in an iCal Calendar.
- Use Applescript to grab all of those events and parse their date/time/wake/sleep info into a table.
- Spit that data into a shell script that runs a separate "pmset" command for each event.
To get really fancy, your application could also read, or perhaps even learn to directly write to, the
/Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist file, which stores a human-readable list of scheduled sleep / wake events.
Maybe you are looking for
-
I have to say that I have had problem after problem with my suite of Apple computers and mobile devices. When I search for solutions I find masses of users with the same problems. Not one of the obvious problems is answered with workable fixes. <Edit
-
Hi gurus, We applied the bw sp SAPKW35018 and when I open the WAD theres no stylesheets available, it display all the .css options but none have a stlye, this is a big issue because when i try to view it in the browser no style is presented. Aditiona
-
Query taking more response time
Hi Masters, Today i am tuning One Query The Following points are the Info regarding my query. Table1- has 100 million records. Table2 - has 7000 records. I am Using table2 as Driving table. I used the Ordered, index hint, use_nl hint and all My Query
-
the converted word document is not easily edited without having to correct the scewing, etc. The final edited document is not suitable.
-
I have often received the alert box that the selected server can not send the mail and I have to change the server,or wait, or restart mail to get it to work. This is annoying, but I have dealt with it (although I'd like to know what's going on). But