How can I trim a variable?
I have an applescript with a variable containing the POSIX path of a file. I would like to assign a variable with the POSIX path of the folder that contains the file.
eg :
pathVariable is "/Users/name/Desktop/file.ext"
then
folderVariable should be "/Users/name/Desktop/"
can anyone think of a way to assign folderVariable within an applescript?
Thanks in advance!
There are a couple of ways to do this - one uses the Finder to get the container (somewhat confusing with POSIX strings since it uses aliases), and the other uses AppleScript's text item delimiters to strip off the end item of the path:
<pre title="this text can be pasted into the Script Editor" style="font-family: Monaco, 'Courier New', Courier, monospace; font-size: 10px; padding: 5px; width: 720px; color: #000000; background-color: #E0E0E0; overflow: auto">set TestFile to POSIX path of ((choose file without invisibles) as string) -- get a POSIX path string
tell application "Finder" to set MyFinderPath to POSIX path of (container of (POSIX file TestFile as alias) as alias)
log "Finder container: " & MyFinderPath
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set MyPosixPath to reverse of (rest of (reverse of text items of TestFile)) & "" as string
set AppleScript's text item delimiters to TempTID
log "Text Item Delimiters: " & MyPosixPath
</pre>
Similar Messages
-
How can I use environment variables in a controller?
Hi all,
How can I use environment variables in a controller?
I want to pass a fully qualified directory and file name to FileInputStream and would like to do it by resolving an env variable, such as $APPLTMP.
Is there a method somewhere that would resolve this??
By the way,Did anyone used the class of "oracle.apps.fnd.cp.request.RemoteFile"?
The following is the code.
My EBS server is installed with 2 nodes(one for current,and other is for application and DB).I want to copy the current server's file to the application server's $APPLTMP directory. But the result of "mCtx.getEnvStore().getEnv("APPLTMP")" is current server's $APPLTMP directory.
Can anyone help me on this?
private String getURL()
throws IOException
File locC = null;
File remC = new File(mPath);
String lurl = null;
CpUtil lUtil = new CpUtil();
String exten;
Connection lConn = mCtx.getJDBCConnection();
ErrorStack lES = mCtx.getErrorStack();
LogFile lLF = mCtx.getLogFile();
String gwyuid = mCtx.getEnvStore().getEnv("GWYUID");
String tmpDir = mCtx.getEnvStore().getEnv("APPLTMP");
String twoTask = mCtx.getEnvStore().getEnv("TWO_TASK");
// create temp file
mLPath = lUtil.createTempFile("OF", exten, tmpDir);
lUtil.logTempFile(mLPath, mLNode, mCtx);
Thanks,
binghaoHowever within OAF on the application it doesn't.
what doesnt work, do you get errors or nothing ?XX_TOP is defined in adovars.env only. Anywhere else this has to go?
No, it is read from the adovars.env file only.Thanks
Tapash -
How can I set a variable number of values in a SQL IN clause?
Hi,
How can I set a variable number of values in a SQL IN clause without having to change the text of the SQL statement each time?
I read the link http://radio.weblogs.com/0118231/2003/06/18.html. as steve wrote.
SELECT *
FROM EMP
WHERE ENAME IN (?)
But we need the steps not to create type in the system and would there be any other solution if we would like to use variable number of values in a SQL IN clause ?
We are using JDeveloper 10.1.3.2 with Oracle Database 10.1.3.2
Thanks
RajHi,
can you please explain why the solution from steve is not the right solution for you.
regards
Peter -
How can I access global variables in a loaded Applescript?
How can I access global variables in a loaded script, in Xcode, ApplescriptObjC? Basically, I have a global variable defined in my parent script using "property", and I need to modify objects connected to those variables inside of a loaded script.
Example:
Parent script:
script AppDelegate
property myTextField : missing value
//linked to a text field object
tell myScript to myAwesomeHandler_()
end script
Loaded script:
on myAwesomeHandler_()
myTextField's setStringValue_("The new Xcode is so glitchy ugh")
//changes value of linked text field of parent script
end myAwesomeHandler_
The problem is, the variable is undefined in the Loaded script, and I need it to have the same value as the parent script, and I don't want to pass the variable through the Handler. Any ideas?I think want you are looking to do will need to be done in two steps. Because myTextField needs to be a property for the ObjectiveC part of the code you cannot turn it into a global.
However if you make a temporary variable global assign the string to it in the handler then set myTextField off of it.
global myTextFieldGlobal
script AppDelegate
property myTextField : missing value
//linked to a text field object
tell myScript to myAwesomeHandler_()
myTextField's setStringValue_(myTextFieldGlobal)
end script
on myAwesomeHandler_()
set myTextFieldGlobal to "The new Xcode is so glitchy ugh"
//changes value of linked text field of parent script
end myAwesomeHandler_
I know you stated you did not want the handler to return a value but I have to ask why? Global's, imo, are not a good idea and really should be used as a last resort.
One other possibility is to pass a reference to the property to the handler. Not sure if that works in AS of if that would satisfy our requirement of not passing the variable through the handler
<edit>
Another though have you tried to define the property outside the script? That is
property myTextField : missing value
script AppDelegate
Not sure if that will work.
You might also want to have a look at Scope of Properties and Variables Declared in a Script Object -
using action script 2 how can i send a variable value to a dynamic textbox on a different keyframe?
Thanks for your swift response.
That sounds like a good solution, but the code I have on frame 2 is this
timer = 0;
countup = function(){
timer++;
countupInterval = setInterval(countup,100);
If I added the same actionscript to frame 3 which has a dynamic textbox with a variable timer attached wouldn't it just put the timer back to 0? What I want is the last known value that was given when it was in frame 2.
I am thinking of temple run here, I am trying to caculate the total distance(set in the timer variable) from the previous try.
Hope this makes sense.
Chazwick -
How can I transfer a variable to regexp_replace function
Hi,
In addition to my question from yesterday, I went up one (little) level for the next question.
How can I transfer a variable to regexp_replace function?
I am getting the value of the variables from from APEX Items.
The value of item :P105_OLD_NAME should be replaced with the value from :P105_NAME APEX item.
The projects in PROJECT_NAME field are separated by “:”
select * from infoux_proj;
HOSTNAME PROJECT_NAME
host1 proj2:proj1
host3 proj1
host4 proj12:proj1
host5 proj3
host2 proj1:proj3:sunproj1
this is my code:
declare
v_old_proj_list varchar(100);
v_new_proj_list varchar(100);
begin
for host in (select a.hostname, project_name
from infoux_proj a,
(select hostname
from PROJECT_NAMES_WITH_HOSTNAMES
where name = :P105_OLD_NAME ) b
where a.HOSTNAME=b.hostname)
loop
select project_name ,
regexp_replace(project_name,'(^|:)(:P105_OLD_NAME)(:|$)','\1:P105_NAME \3') new_project
into v_old_proj_list, v_new_proj_list
from infoux_proj
where hostname=host.hostname;
update infoux_proj
set project_name=v_new_proj_list
where hostname=host.hostname;
end loop;
end;
Thanks,
SheliHi, Sheli
Inside quotes, :p105_old_name will not be taken as a variable name. If you want to use the value of :p105_old_name in a string which its otherwise a literal, then you can concatenate the variable to the literal parts, using the || operator.
You can do soemthing like this:
REGEXP_REPLACE ( project_name
, '(^|:)(' || :P105_OLD_NAME
|| ')(:|$)'
, '\1' || :P105_NAME
|| ' \3'
) AS new_projectI'll bet there's a much simpler way to do what you want. Instead of having two SELECTs, a cursor FOR loop and an UPDATE, you can probably do what you need to with just a single UPDATE or MERGE. It would be more efficient, too. If you'd like help, post CREATE TABLE and INSERT statements for all relevant tables and columns azs the exist before this code is run, a couple of sets of values for the bind variables, and the results you'd like to see (that is, the contents of the changed table) for each set, given the same sample data.
Always say which version of Oracle you're using. -
How can I get the variable with the value from Thread Run method?
We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
How can I get the variable with the value?
This is sample code:
public class SampleSynchronisation
public static void main(String df[])
sampleThread sathr= new sampleThread();
sathr.start();
System.out.println("This is the value from the run method "+sathr.x);
// I should get Inside the run method::: But I get only Inside
class sampleThread extends Thread
public String x="Inside";
public void run()
x+="the run method";
NB: if i write the variable in to a file I am able to read it from external method. This I dont want to doWe want to access a variable from the run method of a
Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
Even
though I make the variable as public /public static, I
could get the value till the end of the run method
only. After that scope of the variable gets lost
resulting to null value in the called method/class..
I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
public class SampleSynchronisation
public static void main(String[] args)
SampleSynchronisation app = new SampleSynchronisation();
public SampleSynchronisation()
MyRunnable runner = new MyRunnable();
new Thread(runner).start();
// yield this thread so other thread gets a chance to start
Thread.yield();
System.out.println("runner's X = " + runner.getX());
class MyRunnable implements Runnable
String X = null;
// this method called from the controlling thread
public synchronized String getX()
return X;
public void run()
System.out.println("Inside MyRunnable");
X = "MyRunnable's data";
} // end class MyRunnable
} // end class SampleSynchronisation>
public class SampleSynchronisation
public static void main(String df[])
sampleThread sathr= new sampleThread();
sathr.start();
System.out.println("This is the value from the run
method "+sathr.x);
// I should get Inside the run method::: But I get
only Inside
class sampleThread extends Thread
public String x="Inside";
public void run()
x+="the run method";
NB: if i write the variable in to a file I am able to
read it from external method. This I dont want to do -
How can I get the variable with the value from Thread's run method
We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
How can I get the variable with the value?
This is sample code:
public class SampleSynchronisation
public static void main(String df[])
sampleThread sathr= new sampleThread();
sathr.start();
System.out.println("This is the value from the run method "+sathr.x);
/* I should get:
Inside the run method
But I get only:
Inside*/
class sampleThread extends Thread
public String x="Inside";
public void run()
x+="the run method";
NB: if i write the variable in to a file I am able to read it from external method. This I dont want to doYour main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.
-
How can I convert the variable expression stored as string back to variable expression
How can I convert the variable expression stored as string back to variable expression?
I am storing the expression enterd in the TSExpresssionEditControl as simple string and want to convert back to expression since I want to get the data type of that expression.pritam,
I'm not sure what you're trying to do exactly. If you are trying to get the value of a variable and you only have the name of value in a string, then you can use Evaluate() to get its value. If you want the data type, my advise is to use the GetPropertyObject() API method and just pass in the loop up string. Then you'll have a handle to the data object and then proceed from there.
Regards,
Song D
Application Engineer
National Instrument
Regards,
Song Du
Systems Software
National Instruments R&D -
How can I trim audio in a slide show
How can I trim the music in a slide show
You need Photoshop Elements + Premiere Elements in order to trim and mix audio tracks.
Or in PSE make the timings and transitions match the music track. -
How can I create a variable size array?
How can I create a variable size array?
ok then how can i create a new vector object?If you don't know that, you need to go back to your text book and study some more. Or read the tutorial on the basics of Java: http://java.sun.com/docs/books/tutorial/java/index.html
After reading that you can move on to: http://java.sun.com/docs/books/tutorial/collections/index.html
Anyway, the answer to your question is, of course:
Vector v = new Vector();(But you should probably use ArrayList instead of Vector.) -
How can i pass a variable instead of a table name in the Select statement.
Dear all
how can i pass a variable instead of a table name in a select statement ?
Example :-
Begin
P_get_procedure_tname (aap_name,otable_name);--It will take an application name and will return a table name
Select col1 into ocol1
from ---- here i want to pass the variable OTABLE_NAME
End;How can i pass this ?Hi,
You can use dynamic sql.
EXECUTE IMMEDIATE 'SELECT COL1 INTO ' || OCOL1 || ' FROM " || OTABLE_NAME;
{code}
cheers
VT -
How can i store a variable to a file?
for some reason i can't find much on writing to files, is
this not possible?
and if it isnt possible, how can i keep a variable? i don't
want the variable to reset to 0 every time someone loads a new
instance of the page.
also, for some reason.. it seems to me that if statements
dont work as they should. the vote() function always executes the
countVote() function even if choice doesn't = ans.
anyone know what im doing wrong
example..
private function vote(choice):void {
text1.text=choice
if (choice=ans){
countVote();
private function countVote():void {
total=total+1
totalS=total.toString();
text2.text=totalS
text2 displays the total count and every time i submit the
vote, the count goes up no matter what i choose
i also get a warning for all of the variables saying
"1084: var 'total' will be scoped to the default namespace:
sv1: internal. It will not be visible outside of this package."
(sv1 is the name of the project)
how to i make it visible outside of the package?In this case, the if statement will not work as you intended.
You need to use the double-equals, ie, if (choice == ans)
Also, the flash player is inside a sandbox for security
reasons. Consequently, you can not write directly to files. To get
around this, make a call to a php, python, java or .net script
residing on the webserver that will write to a file for you. You
can do this using the HTTPService object. -
How can i Refresh my Variable Screen In WAD templet?
Hi Experts,
When i execute a WEB Templet giving Variable Selection Inputs , the Variable input values gets stored in the Variable Tab and will not change untill i Change it.
Example
Variable input 0PLANT 5030(this 5030 is the input where i give in the variable selection screen)
when i click back on the intrenet Explorer , this 5030 will be there stored in the 0PLANT tab.
can any one give me solution how can i refresh the variable screen in the WAD
Santosh NagarajTis might be a browser feature - the variable values tend to get stored - you could look at implementing DSM ( through portal ) or try making your template stateless and see if the value changes...
-
How can I define global variable in user exit whic I can use anywhere.
Hi all,
How can I define global variable( Table ) which I can use when it come back to same user exit where I defined and stored some data.
What I mean is I want to define 1 global table.
In user exit when it comes I store some information. and again when it will come I will have that stored information so I can use it.
Thanks a lot in advance.You can use EXPORT TO MEMORY ID and IMPORT FROM MEMORY ID Statement for this.
EXPORT T_ITAB FROM T_ITAB TO MEMORY ID 'ABC'.
IMPORT T_ITAB TO T_ITAB FROM MEMORY ID 'ABC.'
Maybe you are looking for
-
GroupWise recent sent items do not show in sent folder
On GroupWise Whenever I check my sent items folder I am only able to see messages from 2004. I am only able to see my recent sent items from GroupWise Remote. Whenever I am connected locally I can never see my recently sent messages. Any help is appr
-
I just flew on a airplane and when I turned my iPad on the screen went red
I was wondering why my iPad screen would turn red. I just flew home and turned it on. I did lay it in the screening tray would that affect it?
-
updating to Mavericks has had ita fair share of nuances.. need help with BOUNCE restorattion in mail
-
IVE GOT MY IPODTOUCH I HAVE THE ID BT IVE GOT SOME DIFFICULTIES TO INSERT IT INTO MY DEVICE
I have a problem in inserting my Apple ID into my ipod touch
-
At a recent demo, Oracle showed how IFS automatically expanded the contents of a zip file uploaded into the db. Now that I have 9iFS, I can't find how to do it... any help?