HELP with Shell scripting!!!
Hello all,
I'm very new to shell scripting and I'm trying to learn a little more as I go on. I'm trying to write a shell script to create a symbolic link to an application and have it moved to the current user's desktop. I've been doing some testing with the default applications installed on Leopard here is what I have so far...
ls -s /Applications/Chess.app
I've trying using cp commands, but I continue to get error messages. The above script does create a symbolic link to my home directory, but I want to then move it from the home directory to the current user's desktop. Can anyone lead me any further?
Thanks in advance for any help!
I'm also having a problem making my shell script unix executable. I have tried chmod +x path/to/script and then I killall Finder but nothing happens. Am I doing something wrong?
Are you trying to make your script "Double-Clickable"?
Then you still need to do the
chmod +x /path/to/script
But that will just make it something you can run from a shell.
If you want double-clickable, you can create an Automator app
Applications -> Automator -> Run Shell Script
Or you can download the free Platypus utility that will make any script a double-clickable applications.
Or you can name your script
myscript.command
where the .command is the important part, which the Finder will treat as something it should execute as a shell script when double-clicked.
And no killing Finder. They will work without messing with the Finder.
Personally, I prefer the Automator app or Platypus. Well I also work a lot in the shell, and I execute scripts as script in the shell all the time, so I only create a lot more scripts that get executed as commands than I do double-clickable scripts.
Similar Messages
-
Can anyone here help me (getting my feet wet) with an addition to a profile (applmgr) that I am trying to make - in the form of a shell script.
I have the following lines in the profile file - but each time I log into the server as applmgr, I get the error following
if $HOSTNAME=hostname1
tnen
. /u01/xxees/EBST/apps/apps_st/appl/APPSEBST_$HOST.env
fi
if $HOSTNAME=hostname2
./u01/xxees/EBST2/apps/apps_st/appl/APPSEBST_$HOST.env
fi
The error message I am getting us
-bash: /local/ebsuser/applmgr/.profile: line 39: syntax error near unexpected token `fi'
-bash: /local/ebsuser/applmgr/.profile: line 39: `fi'
Thank you all.
Edited by: 864641 on Jun 13, 2012 1:49 PMFrom the Error Message at line Number 38, I feel that, the file /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOST.env (where $HOST can be "hostname01" or "hostname02") has been modified and has unmatched if.
Also, If you are using the variable HOSTNAME, I feel that the env file should be like /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env in which case your script will be like:
if [$HOSTNAME == "hostname01"]; then
. /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
fi
if [$HOSTNAME == "hostname02"]; then
. /u01/xxees/EBSTEST2/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
fi
Hope that this two things will help in resolving the issue. -
Need help with shell scripting and Patching
Hello all,
I am a very new Oracle DBA and I just have an interview where i have been ask two questions that i have no idea of what it is
1/ What is shell scripting and how do you do shell scripting?
2/ What is Patching and how do you do patching?
Can some one help to have a very good understanding of these tow questions?
Thanks a lot1/ What is shell scripting and how do you do shell scripting?shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.
Shell script defined as:
"Shell Script is series of command written in plain text file. Shell script is just like batch file in MS-DOS
for example:- for taking backup, health check and doing some task Operating system level or Oracle database level we can create shell script and schedule a cron job
2/ What is Patching and how do you do patching?for example ,in windows while using sometimes you might face an issue/error and it gives pop up error message would like to send/report this error to microsoft? microsoft will send you a fix for that. lot of fixes for errors/bugs are released as patches.( n number of patches with newer features are releases as new version)
likewise in oracle for resolving bugs we should have to apply patch.
patch is basically a fix for a bug/bugs. we need to use opatch utility to apply the paches.
hope, this helps you -
Help with shell script: Find Recently Modified Directories
I'm trying to do something that appears to be beyond my capacity to figure out on my own. I'm hoping that someone more skilled than I at scripting can help.
Challenge
I'm trying to build a script that finds directories and gzips each individually, but only if they've been modified within the last, say, 7 days.
Context
The idea is to create a set of gzipped directories that can then be uploaded to a remote server for backup and archival purposes. Since the parent directory is 8+ GB in size, and 99% of the contents does not change from week to week, I want to identify, zip, and upload only the directories that have been modified recently. (Uploading is outside the scope of this script).
*Cut to the Chase*
In plain english, my script might look like:
1) find sub-folders contained within "~/Sites/" that have been modified within the last 7 days; do not go more than 1 level deep (i.e., return only the top level folders within ~/Sites/)
2) loop through the returned list and gzip each directory
I'm hoping that this can be done easily. Automator doesn't provide filters that are granular enough to do this, so I'm thinking bash is the way to go. Any help would be most appreciated, and will be rewarded with all kinds of good karma. =)
-SteveOK, here is an untested and possibly syntactically incorrect Perl script:
#!/usr/bin/perl -w
use strict;
my $siteDir = "$ENV{HOME}/Sites";
# Get all the top-level contents of the Sites directory.
opendir(SITES, $siteDir) or die "Couldn't open $siteDir folder.
my @siteContents = readdir SITES;
closedir SITES;
# Reset my script startup time to be 7 days ago.
$^T = time - (6060*247);
# Now find all the modified directories since then.
my @modifiedSiteDirs = grep { -d "$siteDir/$_" and -M "$siteDir/$_" < 7 } @siteDirs;
foreach my $modifiedSiteDir (@modifiedSiteDirs)
system qq{tar zcf "$modifiedSiteDir.tar.gz" $modifiedSiteDir};
Actually, I did just test it with only a printout instead of executing tar and it works. I'm not sure of the path to tar on MacOS X. You may have to add that. -
Checking database availability with shell script
can anyone help with a script that checks for database availability before 10 P.M and 7 A.M at 5 minites interval and starts a SQL Load of a table once the db is available.
I have no Shell script experience at all but I can amend an already written script.
Please Help !!Dear Timothy,
Within the Oracle software you have installed on your machine, there is a script called "dbstart" within the <ORACLE_HOME>/bin directory. This script provided by Oracle can be easily modified to check whether the server is up and should help solve your problem.
Ciao! -
Need to enable Usage Tracking With Shell Script
Hi All
I have patch 11.1.1.6.7 installed in system. I have Redhat linux 6 sytem
Can we enable usage tracking with shell script ? if yes how ?
Thanks
Samit BaghlaHi Samit,
No you can not as per my info because everything to be configured for the usage tracking is via repository and enterprise manager. You need to invoke it in em and rpd you need to do modelling. I still did not understand that why you want to create the shell script !!
Thanks,
Amol
(Please mark this answer, if you found correct) -
SQL in Connection with shell scripts
Hello everyone,
I have a conceptual question:
If people like to implement their SQL-Scripts attached on a shell script(Ruby, Perl, or even OS-Shell), what are actually the benefits doing this? Can someone please give me a szenario, which is very effectively if we do it with combination with shell-script.
My second question: does oracle sql developer support this shell combination?
Thank you..Wrapping sql script in a shell script provides flexibility. Shell can provide better parameter validation than SQL, better output handling, and better error trapping. Personally I would have the sql script separately for purist modularisation reasons, but you can merge the two.
e.g.
getdate.sql
select sysdate from dual;getdate.sh can look like this
sqlplus user/pwd @getdateor
sqlplus user/pwd <<EOSQL
@getdate
EOSQLor
sqlplus user/pwd <<EOSQL
select sysdate from dual;
exit
EOSQLMy preference would be for either of the first two.
You can use various shell facilities to capture the output of the sql statement for use elsewhere. Variations of the above example can be use to get the current database date and time into the shell environment for use in other queries, or in the shell itself.
You can run SQL Developer from the command line, but the tool of choice for command line is SQL Plus. -
I need help with this script please ASAP
So I need this to work properly, but when ran and the correct answer is chosen the app quits but when the wrong answer is chosen the app goes on to the next question. I need help with this ASAP, it is due tommorow. Thank you so much for the help if you can.
The script (Sorry if it's a bit long):
#------------Startup-------------
display dialog "Social Studies Exchange Trviva Game by Justin Parzik" buttons {"Take the Quiz", "Cyaaaa"} default button 1
set Lolz to (button returned of the result)
if Lolz is "Cyaaaa" then
killapp()
else if Lolz is "Take the Quiz" then
do shell script "say -v samantha Ok starting in 3…2…1…GO!"
#------------Question 1-----------
display dialog "Around age 11, many boys left their fathers to become…" buttons {"Scholars", "Warriors", "Apprentices"}
set A1 to (button returned of the result)
if A1 is "Apprentices" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#----------Question 2--------
display dialog "Most children were taught
to read so that they could understand the…" buttons {"Music of Mozart", "Bible", "art of cooking"}
set A2 to (button returned of the result)
if A2 is "Bible" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#------------Question 3---------
display dialog "In the 1730s and 1740s, a religious movement called the_______swept through the colonies." buttons {"Glorius Revolution", "Great Awakening", "The Enlightenment"}
set A3 to (button returned of the result)
if A3 is "Great Awakening" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#-----------Question 4--------
display dialog "_______ was
a famous American Enlightenment figure." buttons {"Ben Franklin", "George Washington", "Jesus"}
set A4 to (button returned of the result)
if A4 is "Ben Franklin" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#----------Question 5-------
display dialog "______ ownership gave colonists political rights as well as prosperity." buttons {"Land", "Dog", "Slave"}
set A5 to (button returned of the result)
if A5 is "Land" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#---------Question 6--------
display dialog "The first step toward guaranteeing these rights came in 1215. That
year, a group of English noblemen forced King John to accept the…" buttons {"Declaration of Independence", "Magna Carta", "Constitution"}
set A6 to (button returned of the result)
if A6 is "Magna Carta" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#----------Question 7--------
display dialog "England's cheif lawmaking body was" buttons {"the Senate", "Parliament", "King George"}
set A7 to (button returned of the result)
if A7 is "Parliament" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#--------Question 8-----
display dialog "Pariliament decided to overthrow _______ for not respecting their rights" buttons {"King James II", "King George", "King Elizabeth"}
set A8 to (button returned of the result)
if A8 is "King James II" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#--------Question 9------
display dialog "Parliament named ___ and ___ as England's new monarchs in something called ____." buttons {"William/Mary/Glorius Revolution", "Adam/Eve/Great Awakening", "Johhny/Mr.Laphalm/Burning of the hand ceremony"}
set A9 to (button returned of the result)
if A9 is "William/Mary/Glorius Revolution" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#---------Question 10-----
display dialog "After accepting the throne William and Mary agreed in 1689 to uphold the English Bill of _____." buttons {"Money", "Colonies", "Rights"}
set A10 to (button returned of the result)
if A10 is "Rights" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#---------Question 11------
display dialog "By the late 1600s French explorers had claimed the ___ River Valey" buttons {"Mississippi", "Ohio", "Hudson"}
set A11 to (button returned of the result)
if A11 is "Ohio" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#------Question 12---------
display dialog "______ was sent to ask the French to leave 'English Land'." buttons {"Johhny Tremain", "George Washington", "Paul Revere"}
set A12 to (button returned of the result)
if A12 is "George Washington" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#---------Question 13-------
display dialog "_____ proposed the Albany Plan of Union" buttons {"George Washingon", "Ben Franklin", "John Hancock"}
set A13 to (button returned of the result)
if A13 is "Ben Franklin" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#--------Question 14------
display dialog "The __________ declared that England owned all of North America east of the Mississippi" buttons {"Proclomation of England", "Treaty of Paris", "Pontiac Treaty"}
set A14 to (button returned of the result)
if A14 is "" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#-------Question 15-------
display dialog "Braddock was sent to New England so he could ______" buttons {"Command an attack against French", "Scalp the French", "Kill the colonists"}
set A15 to (button returned of the result)
if A15 is "Command an attack against French" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
#------TheLolQuestion-----
display dialog "____ is the name of the teacher who runs this class." buttons {"Mr.White", "Mr.John", "Paul Revere"} default button 1
set LOOL to (button returned of the result)
if LOOL is "Mr.White" then
do shell script "say -v samantha Congratulations…you…have…common…sense"
else
do shell script "say -v alex Do…you…have…eyes?"
#------END------
display dialog "I hope you enjoyed the quiz!" buttons {"I did!", "It was horrible"}
set endmenu to (button returned of the result)
if endmenu is "I did!" then
do shell script "say -v samantha Your awesome"
else
do shell script "say -v alex Go outside and run a lap"
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end ifUse code such as:
display dialog "Around age 11, many boys left their fathers to become…" buttons {"Scholars", "Warriors", "Apprentices"}
set A1 to (button returned of the result)
if A1 is "Apprentices" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
return
end if
#----------Question 2--------
display dialog "Most children were taught to read so that they could understand the…" buttons {"Music of Mozart", "Bible", "art of cooking"}
set A2 to (button returned of the result)
if A2 is "Bible" then
do shell script "say -v samantha Correct Answer"
else
do shell script "say -v samantha Wrong Answer"
return
end if
(90444) -
Pl/sql procedure with shell script
Hi Guys,
I will be updating some of the columns in the database thru SQL UPDATE stament. I want to make this process automatic. I.e instead of running manually this uodate process, i want to write a unix script which run on cron job. In the update stament I have to compare date like e_create_date > to_date (........, 'yymmdd') and date should be 2 days previous then to date and I would ike to create the spool file which I would like to send through mail.the script will run automatically.
I am confused how to write shell script & sql procedure and how to call it inside the shell script. How can this be done.
Help Appreciated.
Thanks
sonusave the Store procedure as a create_SP.sql in OS
save another testrun.sql
as follows
begin
sp_test('&p_test');
end;
If you are on a Unix or Solaris OS then
open a Shell Script as follows :
and name as test.sh or test.ksh
var='SYSTEM'
export var
sqlplus username/password
@create_SP.sql
-- this created a store procedure on the database
@testrun.sql $var
This will execute the SP with parameter from OS Variable. -
Hi,
I have a requirement need a help.
Requirement states like this:
I need to write a shell script through which I need to search a huge lines code and to find out following information :
1. Total No of lines of the code
2. No of DML statements (select,update,insert, delete) used like how many SELECT, How many UPDATE etc used in it.
3. No of base apps tables referenced like How many tables starting with "CMF_" is present.
4. No of procedure calls like how many procedures starting with "PROC_" used.
Can anyone help me in this ? I need to script.
My Unix version is :
$ uname -a
SunOS appsnet 5.6 Generic_105181-21 sun4u sparc SUNW,Ultra-4
Thanks in advance
[email protected]What you need here is a AWK script. This script will read the input as the source file (as command line
argument or as standard input), and process each like of the file read to look for the different patterns
in that line (looking for example if the line contans "SELECT " or "INSERT " etc...) and increment its
corresponding count. At the end of the script in the END section you can get the number of lines with the
NR awk inbuilt variable.
Hope this helps.
Hi,
I have a requirement need a help.
Requirement states like this:
I need to write a shell script through which I need to search a huge lines code and to find out following information :
1. Total No of lines of the code
2. No of DML statements (select,update,insert, delete) used like how many SELECT, How many UPDATE etc used in it.
3. No of base apps tables referenced like How many tables starting with "CMF_" is present.
4. No of procedure calls like how many procedures starting with "PROC_" used.
Can anyone help me in this ? I need to script.
My Unix version is :
$ uname -a
SunOS appsnet 5.6 Generic_105181-21 sun4u sparc SUNW,Ultra-4
Thanks in advance
[email protected] -
Help with Apple Script rewrite
I can't wrap my brain around applescript. I found this program mp3gain. It is written in applescript. I just need it to go to folder abc download and run, then save it to a folder names abc done. I can reset the db from the script. Any help would be great. All the itunes stuff can be deleted.
-- MacMP3Gain.applescript
-- MacMP3Gain
-- Created by Bery Rinaldo on Tue Jan 14 2003.
-- Copyright (c) 2003-2005 Bery Rinaldo. All rights reserved.
-- This AppleScript is used to wrap the command line version of mp3gain with a quaint GUI.
-- This program is free software; you can redistribute it and/or modify it under the terms
-- of the GNU General Public License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License along with this program; if not,
-- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-- This program includes a binary version of aacgain downloaded from here
-- http://www.hydrogenaudio.org/forums/index.php?act=Attach&type=post&id=1461
-- aacgain version 1.4.0, derived from mp3gain version 1.4.6
-- copyright(c) 2001-2004 by Glen Sawyer
-- AAC support copyright(c) 2004 David Lasker, Altos Design, Inc.
-- uses mpglib, which can be found at http://www.mpg123.de
-- AAC support uses faad2 (http://www.audiocoding.com), and
-- mpeg4ip's mp4v2 (http://www.mpeg4ip.net)
-- Check out the MP3Gain/AACgain web sites:
-- http://mp3gain.sourceforge.net/
-- http://altosdesign.com/aacgain/
-- Version 1.0 - Initial release
-- Version 1.01 - Added status updates to display while mp3gain is running
-- Version 1.1 - 13-Feb-2003 - Added iTunes playlist support
-- Version 1.2 - 18-Feb-2003 - Added "Process Sub-folders" option to process all folders below the selected folder.
-- Version 1.3 - 20-Feb-2003 - Fixed program hang when "Allow Clipping" checkbox was unchecked.
-- Version 1.4 - 23-Feb-2003 - Added target MP3 Gain dB value, added preferences file support for all controls
-- Version 1.5 - 26-Feb-2003 - Integrate "Be Nice" feature from Michael Heinz. Added "Cancel" feature.
-- Version 1.6 - 28-Feb-2003 - Minor GUI tweaks to "Be Nice" an "Target" buttons to disable while running.
-- Version 1.7 - 01-Nov-2003 - Update to mp3gain 1.4.3, use -k (autoClip) option when "Allow Clipping" is unchecked
-- Version 1.8 - 09-Nov-2003 - Update run_mp3gain.pl to handle iTunes 4 playlists
-- Version 1.9 - 23-Aug-2005 - Update for Tiger & AAC
property ref_folder : ""
property ref_playlist : ""
property running : false
property mp3gain : ""
property run_mp3gain : ""
on clicked theObject
if name of theObject is "Start" then
if running is true then
set title of button "Start" of window "MainWindow" to "Start"
try
set pids to do shell script "ps -auxww | egrep \"" & run_mp3gain & "|" & aacgain & "\" | grep -v grep | awk '{ print $2 }' | xargs kill"
end try
set running to false
tell progress indicator "BusyBar" of window "MainWindow" to stop
set visible of progress indicator "BusyBar" of window "MainWindow" to false
tell window "MainWindow" to update
set contents of text field "StatusMessage" of window "MainWindow" to "Processing aborted."
set enabled of button "Start" of window "MainWindow" to false
set enabled of button "Choose Folder" of window "MainWindow" to true
set enabled of button "Choose Playlist" of window "MainWindow" to true
set enabled of button "Clip" of window "MainWindow" to true
set enabled of button "Sub" of window "MainWindow" to true
set enabled of button "Target" of window "MainWindow" to true
set enabled of button "Nice" of window "MainWindow" to true
set targetchecked to state of button "Target" of window "MainWindow" as integer
if targetchecked = 1 then
set enabled of text field "TargetValue" of window "MainWindow" to true
set targetvalue to 75
try
set targetvalue to contents of default entry "TargetValue" of user defaults as integer
end try
set contents of text field "TargetValue" of window "MainWindow" to targetvalue
else
set enabled of text field "TargetValue" of window "MainWindow" to false
set contents of text field "TargetValue" of window "MainWindow" to 89
end if
set enabled of matrix "ARmatrix" of window "MainWindow" to true
set ref_folder to ""
set contents of text field "FolderPath" of window "MainWindow" to "No folder selected"
set ref_playlist to ""
set contents of text field "PlaylistName" of window "MainWindow" to "No playlist selected"
tell window "MainWindow" to update
else
set clip to (state of button "Clip" of window "MainWindow") as integer
set albumradio to current row of matrix "ARmatrix" of window "MainWindow"
set options to " -q "
if clip = 1 then
set options to options & "-c "
else
set options to options & "-k "
end if
if albumradio = 1 then
set options to options & "-a "
else
set options to options & "-r "
end if
set nicechecked to state of button "Nice" of window "MainWindow" as integer
set targetchecked to state of button "Target" of window "MainWindow" as integer
if targetchecked = 1 then
set targetdb to integer value of text field "TargetValue" of window "MainWindow"
set targetparam to targetdb - 89
set options to options & "-m " & (targetparam as string) & " "
end if
set can_run to false
if ref_playlist is not equal to "" then
set the playlist_text to ""
tell application "iTunes"
set the track_count to the count of tracks of playlist ref_playlist
repeat with z from 1 to the track_count
tell track z of playlist ref_playlist
copy {database ID} to {dbid}
end tell
set the playlist_text to the playlist_text & (dbid as string) & ","
end repeat
end tell
activate
if track_count = 0 then
display dialog "The playlist is empty." buttons {"OK"}
else
set options to options & "-P " & playlist_text
set can_run to true
end if
else
set folder_path to POSIX path of ref_folder
set sub to (state of button "Sub" of window "MainWindow") as integer
if sub = 1 then
set options to options & "-S -F \"" & folder_path & "\""
set can_run to true
else
set command to "cd \"" & folder_path & "\" ; ls *.mp3 *.m4a 2> /dev/null"
set output to do shell script command
if output is equal to "" then
display dialog "No MP3/M4A files were found in the specified folder." buttons {"OK"}
else
set options to options & "-F \"" & folder_path & "\""
set can_run to true
end if
end if
end if
if can_run is equal to true then
set enabled of button "Start" of window "MainWindow" to false
set enabled of button "Choose Folder" of window "MainWindow" to false
set enabled of button "Choose Playlist" of window "MainWindow" to false
set enabled of button "Clip" of window "MainWindow" to false
set enabled of button "Sub" of window "MainWindow" to false
set enabled of button "Target" of window "MainWindow" to false
set enabled of button "Nice" of window "MainWindow" to false
set enabled of text field "TargetValue" of window "MainWindow" to false
set enabled of matrix "ARmatrix" of window "MainWindow" to false
set visible of progress indicator "BusyBar" of window "MainWindow" to true
set uses threaded animation of progress indicator "BusyBar" of window "MainWindow" to true
tell progress indicator "BusyBar" of window "MainWindow" to start
tell window "MainWindow" to update
if nicechecked = 1 then
set command to "nice -n 1 "
else
set command to ""
end if
set command to command & "\"" & run_mp3gain & "\" " & options & " > /tmp/.mp3gain_output 2>&1"
--display dialog command
try
ignoring application responses
do shell script command & "&"
end ignoring
end try
set running to true
set title of button "Start" of window "MainWindow" to "Cancel"
set enabled of button "Start" of window "MainWindow" to true
tell window "MainWindow" to update
end if
end if
else if name of theObject is "Choose Playlist" then
tell application "iTunes"
set allPlaylists to name of user playlists
end tell
activate
set playlist_choice to choose from list allPlaylists with prompt "Which playlist?" multiple selections allowed 0
if playlist_choice is false then --nothing selected, just stop
set ref_playlist to ""
set contents of text field "PlaylistName" of window "MainWindow" to "No playlist selected."
else
set ref_playlist to playlist_choice as string
set contents of text field "PlaylistName" of window "MainWindow" to ref_playlist
set ref_folder to ""
set contents of text field "FolderPath" of window "MainWindow" to ""
set state of button "Sub" of window "MainWindow" to false
set enabled of button "Sub" of window "MainWindow" to false
set enabled of button "Start" of window "MainWindow" to true
tell window "MainWindow" to update
end if
else if name of theObject is "Sub" then
set ischecked to state of button "Sub" of window "MainWindow" as integer
try
set contents of default entry "Sub" of user defaults to ischecked
end try
else if name of theObject is "Clip" then
set ischecked to state of button "Clip" of window "MainWindow" as integer
try
set contents of default entry "Clip" of user defaults to ischecked
end try
else if name of theObject is "Nice" then
set nicechecked to state of button "Nice" of window "MainWindow" as integer
try
set contents of default entry "Nice" of user defaults to nicechecked
end try
else if name of theObject is "Target" then
set targetchecked to state of button "Target" of window "MainWindow" as integer
try
set contents of default entry "Target" of user defaults to targetchecked
end try
if targetchecked = 1 then
set enabled of text field "TargetValue" of window "MainWindow" to true
set targetvalue to 89
try
set targetvalue to contents of default entry "TargetValue" of user defaults as integer
end try
set contents of text field "TargetValue" of window "MainWindow" to targetvalue
else
set enabled of text field "TargetValue" of window "MainWindow" to false
set contents of text field "TargetValue" of window "MainWindow" to 89
end if
else if name of theObject is "ARmatrix" then
set albumradio to current row of matrix "ARmatrix" of window "MainWindow" as integer
try
set contents of default entry "AlbumRadio" of user defaults to albumradio
end try
else if name of theObject is "Choose Folder" then
set ref_folder to choose folder with prompt "Choose the folder where the MP3/M4A files are stored"
set contents of text field "FolderPath" of window "MainWindow" to ref_folder as string
set ref_playlist to ""
set contents of text field "PlaylistName" of window "MainWindow" to ""
set state of button "Sub" of window "MainWindow" to true
set enabled of button "Sub" of window "MainWindow" to true
set enabled of button "Start" of window "MainWindow" to true
tell window "MainWindow" to update
end if
end clicked
on will finish launching theObject
-- display dialog "IN the will finish launching thing"
set running to false
set mypath to POSIX path of (path to me as string)
set aacgain to mypath & "Contents/Resources/aacgain"
set run_mp3gain to mypath & "Contents/Resources/run_mp3gain.pl"
try
make new default entry at end of default entries of user defaults with properties {name:"AlbumRadio", contents:1}
end try
set albumradio to 1
try
set albumradio to contents of default entry "AlbumRadio" of user defaults as integer
end try
set current row of matrix "ARmatrix" of window "MainWindow" to albumradio
my getpreferencebutton("Clip")
my getpreferencebutton("Sub")
my getpreferencebutton("Target")
my getpreferencebutton("Nice")
try
make new default entry at end of default entries of user defaults with properties {name:"TargetValue", contents:89}
end try
set targetvalue to 89
try
set targetvalue to contents of default entry "TargetValue" of user defaults as integer
end try
set contents of text field "TargetValue" of window "MainWindow" to targetvalue
set targetchecked to state of button "Target" of window "MainWindow" as integer
if targetchecked = 1 then
set enabled of text field "TargetValue" of window "MainWindow" to true
else
set enabled of text field "TargetValue" of window "MainWindow" to false
set contents of text field "TargetValue" of window "MainWindow" to 89
end if
set visible of progress indicator "BusyBar" of window "MainWindow" to false
tell window "MainWindow" to update
set visible of window "MainWindow" to true
end will finish launching
on will close theObject
quit
end will close
on changed theObject
set targetdb to integer value of text field "TargetValue" of window "MainWindow"
try
set contents of default entry "TargetValue" of user defaults to targetdb
end try
end changed
on idle
-- display dialog "idle " & running
if running is true then
set psout to ""
set stout to ""
try
set psout to do shell script "ps -auxww | grep \"" & run_mp3gain & "\" | grep -v grep"
set stout to do shell script "grep -a -v '^$' /tmp/.mp3gain_output | tail -1"
end try
if stout = "" then
if ref_playlist is not equal to "" then
set stout to "Processing iTunes playlist " & ref_playlist & " ..."
else
set stout to "Processing folder " & ref_folder & " ..."
end if
else
set stlen to length of stout
if stlen > 75 then
set firstpart to (characters 1 through 30 of stout) as string
set startlast to stlen - 30
set lastpart to (characters startlast through stlen of stout) as string
set stout to firstpart & "..." & lastpart
end if
end if
set contents of text field "StatusMessage" of window "MainWindow" to stout
tell window "MainWindow" to update
if psout is equal to "" then
set running to false
set title of button "Start" of window "MainWindow" to "Start"
tell progress indicator "BusyBar" of window "MainWindow" to stop
set visible of progress indicator "BusyBar" of window "MainWindow" to false
tell window "MainWindow" to update
set contents of text field "StatusMessage" of window "MainWindow" to "Processing complete."
set enabled of button "Start" of window "MainWindow" to false
set enabled of button "Choose Folder" of window "MainWindow" to true
set enabled of button "Choose Playlist" of window "MainWindow" to true
set enabled of button "Clip" of window "MainWindow" to true
set enabled of button "Sub" of window "MainWindow" to true
set enabled of button "Target" of window "MainWindow" to true
set enabled of button "Nice" of window "MainWindow" to true
set targetchecked to state of button "Target" of window "MainWindow" as integer
if targetchecked = 1 then
set enabled of text field "TargetValue" of window "MainWindow" to true
else
set enabled of text field "TargetValue" of window "MainWindow" to false
set contents of text field "TargetValue" of window "MainWindow" to 89
end if
set enabled of matrix "ARmatrix" of window "MainWindow" to true
set ref_folder to ""
set contents of text field "FolderPath" of window "MainWindow" to "No folder selected"
set ref_playlist to ""
set contents of text field "PlaylistName" of window "MainWindow" to "No playlist selected"
tell window "MainWindow" to update
end if
end if
return 1
end idle
on will quit theObject
if running is true then
try
set pids to do shell script "ps -auxww | egrep \"" & run_mp3gain & "|" & aacgain & "\" | grep -v grep | awk '{ print $2 }' | xargs kill"
end try
end if
end will quit
on getpreferencebutton(buttonname)
try
-- this is how to initialize the preferences mechanism...it will not reset the value if one exists already
make new default entry at end of default entries of user defaults with properties {name:buttonname, contents:0}
end try
set value to 0
try
set value to contents of default entry buttonname of user defaults as integer
end try
if value = 1 then
set state of button buttonname of window "MainWindow" to true
else
set state of button buttonname of window "MainWindow" to false
end if
end getpreferencebuttonhi riker123
it is written in applescript, but it is written for AppleScript Studio & Xcode which has now been superseded by AppleScriptObjC & Xcode, used under OSX 10.6
Looking at your Mac specs you could use AppleScript Studio & Xcode
to set this code up, you will find a copy of Xcode on your OSX installer disk.
Not to discourage you but Xcode needs a bit of work to get the hang off,
but that's part of the fun.
Budgie -
Help with a script for elder friend
First off, with apologies, I am not a script familar person at all. I have an elderly friend who is switching to Mac for the first time. I wanted a way to close all open programs, with a prompt to save any open files and then run a Time Machine backup and shut down - preferably without restarting next day with any windows opening automatically. Time Machine is set to run every hour but she's a writer and could lose work if Time Machine doesn't run before shutting down for the night. So I searched and found some small scripts that I tried to put together. I think it works but after Time Machine runs it waits a very long time before shutting down. I'm wondering if some of you kind folks could refine this for me. (I do realize that automator has a quit all programs that I can save as an app but I'm trying to make this a one step 'app' process.)
So what I have is this:
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
do shell script "/bin/bash -c '/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1 &'"
repeat
delay 5
if not IsProcRunning("backupd") then
ignoring application responses
tell application "Finder" to shut down
end ignoring
exit repeat
end if
end repeat
on IsProcRunning(theProc)
try
do shell script "ps auxc | grep \"" & theProc & "\""
return true
on error
return false
end try
end IsProcRunning
.... frankly I don't understand most of this in reality but it's a need I'd like to help her with on her Mac Mini.
Many Thanks,
BrendaFirst off, you're overthinking this. There's no reason why your friend would lose any data by not backing up prior to shutdown (unless she has a flaky hard drive that needs to be replaced). Assuming she's saving her work when she quits her apps, she should be fine.
Second, trying to auto-quit applications is dangerous. You don't check to see if any files need to be saved (there's no easy way to make that check anyway), and that in itself could cause data loss.
Third, time machine has its own command line utility: tmutil. There's no reason to script backupd.
Last, if I remember correctly, whether or not apps and windows reopen at startup can be set on a system-wide or per-application basis.
Give a clearer and more specific description of the goals you're trying to accomplish: what kind of apps are likely to be open, which of them will/might need to save data, what you want the machine to look like on restart, all with details. That would help a lot. -
Help with two scripts - Mounting remote DMG and Checking which network I'm connected to
Hey guys, I need some help with two separate scripts:
1. The first script I'm trying to create to mount a DMG stored remotely on another Mac using an AppleScript or shell script. Using the following:
set cmd to "hdiutil mount 'afp://username:[email protected]/Lion/Users/username/Desktop/Test.sparseim age'"
do shell script cmd
results in the following error:
error "hdiutil: mount failed - not recognized" number 1
I'm not very experienced regarding AppleScript or using hdiutil, could somebody point out what's wrong with my script?
2. The second script I'm working on to try and essentially prevent the 'Could Not Find Server' Finder dialog when a network mount is unavailable. I guess what I'd like it to do is detect which network I'm connected to, and if I'm connected to the correct network, then mount the shares, otherwise just fail silently without any errors. From the searching I've done, using try statements should do this, but they do not, and I'm still presented with an error dialog after the server cannot be found.
Does anybody have any suggestions on this script? Also, I've seen some tips regarding detecting which wireless network the Mac is connected to, which could work, but what about when connected via Ethernet?
Thanks!Edit: I need to clarify on my first script request:
I need to mount the DMG on the remote Mac, not on the Mac I'm running the script from. -
When I run this script from within the applescript edito I get the popup dialog. For some reason it is not finding the file. I know it exists.
try
tell application "Finder"
if exists file "SavedIP.log" in "/Library/Logs" then
set savedIP to do shell script "cat /Library/Logs/SavedIP.log"
end if
end tell
on error errmsg
display dialog errmsg
end try
Thank you for any help.While it's often a good idea to check for files before reading them, it can cause confusion especially when trying to mix Mac-style (colon-delimited) and UNIX-style (slash-delimited) paths, as you've seen.
An alternative is to not bother checking - just read the file and catch any errors that occur (such as the file not existing):
try
set SavedIP to do shell script "cat /Library/Logs/SavedIP.log"
on error
-- file does not exist
end try
In this case the assumption is that the file does exist, but if it doesn't (or if some other error occurs) then you can trap that case in the 'on error' block, and deal with it accordingly. -
Greetings all. Fairly new to scripting but I built the below script to automatically download a file and print it. It works, but what I want to do is eventually turn it into an .app that will run on a schedule (determined by the user). I'm not quite there yet, but what I haven't been able to figure out is how to set a default save location so that once the dialog box asks for the first save location for the file, it will remember that instead of asking every time the script runs (that way when it runs when it is scheduled there is no human input needed). Does this mean i need to run two scrips or can I use an "if then" statement that I haven't figured out. Lastly, if I want to turn it into an app, what's the best way, xcode?
I pasted the script below. Thanks for the help!
set d to ((do shell script "date '+%b%d%y'") & ".puz")
set Puz to "http:[website]" & d
set dest to (choose file name default location (path to desktop) default name d)
do shell script "/usr/bin/curl " & Puz & " -o " & quoted form of POSIX path of dest
delay 5
tell application "[App]"
activate
open (dest & d)
delay 2
tell application "System Events"
keystroke "p" using command down
delay 8 -- (seconds)
keystroke return
delay 8 -- (seconds)
keystroke return
delay 8 -- (seconds)
keystroke return
end tell
delay 30
quit
end tell
Message was edited by: cloongoonIf you want to save data between executions of your app you have two basic approaches.
One is to store a property in your app - the property can be treated like any other variable, except that its value is retained when the app executes/restarts.
The other approach is to write the data out to a file - kind of how any other app would save its own preference/settings data.
Of the two, the property approach is the easier. Just declare a property at the beginning of your script:
property dest:missing value
This will declare dest as a property with an initial value of missing value (essentially null or blank). Your script can now check this variable, and set it to new values, and whatever its value is when the script exits will be saved.
So all you need now is to check the property to see whether it's been defined or not:
if dest = missing value then
-- value has never been set, so set it:
set dest to (choose file name default location (path to desktop) default name d)
end if
Of course, you might want to consider the case where the user wants to change the value - that's not so easy to do
if I want to turn it into an app, what's the best way, xcode?
XCode is the way to go if you want your app to have its own user interface, windows, buttons, widgets, etc. If all you're doing is driving some other app to do your work then saving the script as an app (via File -> Save As... in AppleScript Editor) should do the trick.
Maybe you are looking for
-
T.code for viewing stock at storage bin
Hi all, What is the t. code used for viewing the stock at storge bin?I know this is WM question but your help is appreciated. Regards, Shailendra
-
Hi All, I'm printing from a MacBook Pro using OSX Lion. It says that Officejet Pro 8600 Plus is connected and that the print jop is 100% complete except that nothing comes out of the printer. I've done all of the test prints and they've printed just
-
How to make database read only?
Hi All, I have restored my production database to development. I want to make these database available only for reading purpose means nobody can make any changes to that database only thing is that they can see the data. Is there any feature availabl
-
Dear All: The system is CRM5.0 Unicode based on JAVA+ABAP stack. When we get the backup files, it contains DB files (SQL Server detach files) and whole copy of \usr\sap\<SID> folder (including DVEBMGS51, SCS50, SYS). And we also get the info that the
-
530 authentication required, when send report as email thru Discoverer View
Hi, I got the "530 authentication required" error message when I tried to use the "Send as Email" function to attach a report in the Discoverer Viewer. Could anyone shade some light on this error? Thanks Kevin C